手写代码往最初的工程添加UINavigationController

来源:互联网 发布:360安全认证软件 编辑:程序博客网 时间:2024/05/21 09:12

每个工程代码都要用到UINavigationController,就是在最初刚开始写代码时,下面是一个以后写代码都可以直接粘贴复制的万能模板,现在特意做成笔记了,以后直接拿来用,不要再反复验证了,太费时间了

1、AppDelegate.h不动

2、AppDelegate.m 添加如下红色代码

#import "AppDelegate.h"

#import "RootViewController.h"

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];


    RootViewController *rootViewController = [[RootViewControlleralloc] init];

    UINavigationController *navigationController = [[UINavigationControlleralloc] initWithRootViewController:rootViewController];

    self.window.rootViewController = navigationController; 


    self.window.backgroundColor = [UIColorwhiteColor];

    [self.windowmakeKeyAndVisible];

    return YES;

}


3、新建控制器类RootViewController 继承于UIViewController

  1、 RootViewController.h 不动

  2、 RootViewController.m   添加以下红色代码

- (void)viewDidLoad

{

    [superviewDidLoad];

    self.view.backgroundColor = [UIColorredColor];

}


0 0