在Xcode5中,当创建一个带View的iPhone项目时,默认必须使用Storyboards,不再支持切换xib的checkbox。本文讲解如何手动切换到使用xib来布局。
1,把Main.storyboard从项目中移除
2,添加xib文件到项目中。添加一个新文件,选择View,命名和*ViewContorller相同。
3,把Main storyboard对应的项从plist文件中移除
4,在*AppDelegate中添加类似代码
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
// Override point for customization after application launch.
TestViewController *test = [[TestViewController alloc] initWithNibName:
@"TestViewController"
bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:test];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return
YES;
}
如果ARC关闭的话,以上代码需要手动添加autorelease,这里不详述了。
5,可选:关闭ARC。 在项目的build setting中,找到 Objective-C Automatic Reference Counting, 设置为No
6,把xib关联到对应的ViewController上,否则会报如下错误 NibName[2203:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "loc" nib but the view outlet was not set.'
步骤(参考自 loaded some nib but the view outlet was not set): 1). 点击我们要加载的 xib 文件 2). 在右边选中 File's Owner 3). 在 File's Owner 的 4). 这时候,在File's Owner 的 连接 view 属性(把连线拖动到xib设计器中进行连接),
参考: http://www.cnblogs.com/TivonStone/archive/2012/04/20/2460116.html http://stackoverflow.com/questions/17234172/xcode-5-without-storyboard-and-arc |
本文介绍如何在Xcode5中创建iPhone项目时禁用Storyboard,转而使用xib文件进行界面布局。具体步骤包括移除Main.storyboard、添加xib文件、修改AppDelegate中的代码等。






582

被折叠的 条评论
为什么被折叠?



