1.创建导航控制器
UINavigationController *nav = [UINavgationController alloc] init];
2.创建控制器添加到导航控制器中
1)OneViewController *one = [OneViewControler alloc] init];
[nav pushViewController: one animated:YES];//法1
2)[nav addChildController: one];//法2
3)nav.viewControllers = @[one];//法3
注意:nav.childViewControllers = @[one];//错误,原因:childViewControllers属性readonly
4)UINavigationController *nav = [[UINavgationController alloc] initWithRootViewController: one];//法4
3.获取控制器的栈
nav.viewControllers;
nav.childViewController;
4.获取栈顶控制器
nav.topViewController;
5.导航栏(navigationBar)
1)一个导航控制器只有一个导航条
2)导航条上显示的内容和栈顶的控制器有关,因此,其内容由栈顶的控制器确定
3)控制导航条的内容:
3.1)self.navigtionItem.title = @"This is title";//设置标题
3.2)self.navigtionItem.titleView; //
3.3)self.navigtionItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWith...]; //添加barbutton
3.4)self.navigtionItem.rightBarButtonItems = @[barButton1,barButton2];//添加多个barButton
4)导航控制器的“返回按钮”
4.1)返回按钮显示的内容由上一个控制器控制
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
6.移除当前栈顶控制器
[self.navigationController popViewController popViewControllerAnimated:YES];
7.返回根控制器
[self.navigationController popRootViewControllerAnimates:YES];
8.返回指定控制器
[self.navigationController popToViewController:(UIViewController *) animated:(BOOL)];