如何在Xcode 5中使用xib文件而不是storyboard?

Umu*_*mut 6 xcode storyboard xib ios

我是ios开发的新手,我观看的许多教程都遵循xib方法,因为它们是在XCode 5之前录制的.我如何在单视图应用程序中使用xib方法?当我删除故事板并选择其中一个xib作为主界面时,它无法正常工作.谢谢你的提示.

Dax*_*gar 11

添加新文件,选择cococatouch并选择Objective -C类,然后转到下一个单击.
如果您
在底部显示以下屏幕,则必须选择带有xib的用户界面.接下来

AppDelegate.h:

@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
    ViewController *viewObj;
    UINavigationController *navObj;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic)  ViewController *viewObj;
@property (strong, nonatomic) UINavigationController *navObj;
Run Code Online (Sandbox Code Playgroud)

AppDelegate.m:

@synthesize viewObj,window,navObj;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    viewObj = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    navObj = [[UINavigationController alloc] initWithRootViewController:viewObj];

    window.rootViewController=navObj;
    [window makeKeyAndVisible];

    return YES;
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


bha*_*ari 7

创建新项目时选择清空应用程序模板.
从左窗格中选择Cocoa touch - > objective-c class - >然后给出viewController的名称和Xib用户界面的tick选项.

然后在appDelegate文件应用以下代码:

appDelegate.h文件:

#import <UIKit/UIKit.h>
#import "HomeViewController.h"

@interface HomeAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong,nonatomic)HomeViewController *homeViewController;
@property (strong,nonatomic)UINavigationController *navigationController;
Run Code Online (Sandbox Code Playgroud)

appDelegate.m文件:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];

    self.homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
    self.navigationController = [[UINavigationController alloc]initWithRootViewController:self.homeViewController];
    self.window.rootViewController = self.navigationController;


    [self.window makeKeyAndVisible];
    return YES;
}

  @end
Run Code Online (Sandbox Code Playgroud)