如何新建一个空项目+添加导航视图控制器

解说:使用xcode6的Empty项目模板创建出的项目啥都没有,及不方便。本编就先教大家如何创建一个包含有Target以及Appdelegate等目录的空项目以及添加导航视图控制器。

步骤1:打开xcode6,然后File - > New ->Project,打开后选择Single View Application模板,点击Next,输入项目名称,点击Next,选择保存位置,点击Create。

步骤2:选中项目名称,在配置栏中选择Info栏目,在Custom iOS Target Properties子栏目中删除Main storyboard file base name项(即点击“-”号按钮即可):

步骤3:删除xxxViewController的.h和.m文件,并删除Main.storyboard文件;

步骤4:创建根视图控制器,例如名称为RootViewController(名称自己定义):

在项目名称上右键选择New File,在iOS栏目中,选择Source子栏目,选中Cocoa Touch Class类型的模板,点击Next,在Class项中输入控制器文件名称RootViewController,选中Also create XIB file,点击Next,点击Create。

步骤5:在AppDelegate.m文件中,

添加引用:#import "RootViewController.h"
找到didFinishLaunchingWithOptions方法,清理方法体内容;编辑内容如下:

01.- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
02.self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
03.[self.window makeKeyAndVisible];
04.//第一个视图控制器
05.RootViewController *rootVC = [[RootViewController alloc] init];
06.//将第一个视图控制器作为基栈视图控制器添加到导航视图控制器中
07.UINavigationController *navCtr = [[UINavigationController alloc] initWithRootViewController:rootVC];
08.//将导航视图控制器作为根视图控制器
09.self.window.rootViewController = navCtr;
10. 
11.return YES;
12.}


步骤6:(可选)在RootViewController中的viewWillAppear方法中添加标题:

1.-(void)viewWillAppear:(BOOL)animated
2.{
3.[super viewWillAppear:animated];
4.//添加标题
5.self.navigationItem.title = @"RootViewController";
6.}
原文地址:https://www.cnblogs.com/NSong/p/5359334.html