码迷,mamicode.com
首页 > 其他好文 > 详细

2016 -1 -3 导航控制器的学习

时间:2016-01-04 23:49:09      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

1.效果如下:

技术分享

2.UINavigationController,导航控制器也是UIViewController的子类

(1)在Appdelegate.h中 设置UIWindow及其根控制器为导航控制器,代码如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    oneViewController *oneVC =  [[oneViewController alloc] init];
        oneVC.view.backgroundColor =[UIColor grayColor];
// 设置导航控制器的根控制器 UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:oneVC]; // 设置window为可见 [window makeKeyAndVisible]; // 将AppDelegate的window属性设置为自定义的window self.window = window; // 设置窗口的根控制器为导航控制器 window.rootViewController = nav; return YES; }

 (2)在导航控制器的根controller中设置如下代码:

- (void)viewDidLoad {
    [super viewDidLoad];
//    设置标题

    self.navigationItem.title = @"第一个";
    UIBarButtonItem *camerBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:nil action:nil];
        UIBarButtonItem *secondBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:nil action:nil];
//    self.navigationItem.leftBarButtonItem = camerBtn;
    self.navigationItem.leftBarButtonItems =@[camerBtn,secondBtn];
//    设置返回按钮
#warning 这里是给下一个viewController设置的
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem =backItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

 其他两个控制器中代码基本如上,不在详述。

2016 -1 -3 导航控制器的学习

标签:

原文地址:http://www.cnblogs.com/BJTUzhengli/p/5100445.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!