每个工程代码都要用到UINavigationController,就是在最初刚开始写代码时,下面是一个以后写代码都可以直接粘贴复制的万能模板,现在特意做成笔记了,以后直接拿来用,不要再反复验证了,太费时间了
1、AppDelegate.h不动
2、AppDelegate.m 添加如下红色代码
#import "AppDelegate.h"
#import "RootViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
RootViewController *rootViewController = [[RootViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.window.rootViewController = navigationController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
3、新建控制器类RootViewController 继承于UIViewController
1、 RootViewController.h 不动
2、 RootViewController.m 添加以下红色代码
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
}