- AppDelegate.m
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
RootViewController *root = [[RootViewController alloc] init];
//标题(中间位置)
root.title = @"首页";
//创建导航栏控制器
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:root];
self.window.rootViewController = navController;
[_window makeKeyAndVisible];
leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(selectLeft:)];
self.navigationItem.leftBarButtonItem = leftButton; // 左边的button
rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(selectRight:)];
self.navigationItem.rightBarButtonItem = rightButton; // 右边的button
AddViewController *add = [[AddViewController alloc] init]; // 右button点击事件
//修改字体啥的
self.navigationItem.title = @"返回";
[self.navigationController pushViewController:add animated:YES];
![](https://img.haomeiwen.com/i2285624/b55eb8f995cb3332.png)
- AddViewController.m
self.view.backgroundColor = [UIColor greenColor];
self.title = @"第二页";
![](https://img.haomeiwen.com/i2285624/6bddd5c4d3192d9c.png)
点击右上角的加号,会进入第二页。
![](https://img.haomeiwen.com/i2285624/cf063e89a0328046.png)
点击返回,到第一页。
self.navigationItem.prompt = @"欢迎访问www.baidu.com"; //文本显示在导航栏按钮(在最上方)
![](https://img.haomeiwen.com/i2285624/093eb927470e3239.png)
![](https://img.haomeiwen.com/i2285624/828735083a5282e7.gif)
网友评论