1、新建一個(gè)Single View Application ,并命名。
2.創(chuàng)建好后
選中項(xiàng)目名稱,在配置欄中選擇Info欄目,在Custom iOS Target Properties子欄目中刪除Main storyboard file base name項(xiàng)(即點(diǎn)擊“-”號(hào)按鈕即可):
3.刪除xxxViewController的.h和.m文件,并刪除Main.storyboard文件;
4.創(chuàng)建根視圖控制器
例如名稱為XXXViewController(名稱自己定義):在項(xiàng)目名稱上右鍵選擇New File,在iOS欄目中,選擇Source子欄目,選中Cocoa Touch Class類型的模板,點(diǎn)擊Next,在Class項(xiàng)中輸入控制器文件名稱XXXViewController,選中Also create XIB file,點(diǎn)擊Next,點(diǎn)擊Create。
生成三個(gè)文件
5.在AppDelegate.m文件中
找到didFinishLaunchingWithOptions方法,清理方法體內(nèi)容;
編輯刪除后的內(nèi)容修改如下:(即AppDelegate.m中的文件內(nèi)容)
#import"AppDelegate.h"
#import"XXXViewController.h"
@interfaceAppDelegate()
@end
@implementationAppDelegate
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
self.window= [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];
//第一個(gè)視圖控制器
XXXViewController*rootVC = [[XXXViewControlleralloc]init];
//將第一個(gè)視圖控制器作為基棧視圖控制器添加到導(dǎo)航視圖控制器中
UINavigationController*navCtr = [[UINavigationControlleralloc]initWithRootViewController:rootVC];
//將導(dǎo)航視圖控制器作為根視圖控制器
self.window.rootViewController= navCtr;
[self.windowmakeKeyAndVisible];
returnYES;
}
@end
6.在XXXViewController中的viewWillAppear方法中添加標(biāo)題與背景顏色:
#import"XXXViewController.h"
@interfaceXXXViewController()
@end
@implementationXXXViewController
- (void)viewDidLoad
{
[superviewDidLoad];
self.title=@"XXX";
self.view.backgroundColor= [UIColorgrayColor];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
}
-(void)viewWillAppear:(BOOL)animated
{
[superviewWillAppear:animated];
//添加標(biāo)題
self.navigationItem.title=@"XXXViewController";
}
@end
最后運(yùn)行結(jié)果