ios中导航控制器的使用

时间:2021-08-10 20:41:19

在window中设置导航控制器

FirstViewController *first=[FirstViewController alloc];
//创建导航控制器
UINavigationController *controller=[[UINavigationController alloc]initWithRootViewController:first];
//将导航控制器作为window的根视图
self.window.rootViewController=controller;
//设置导航栏的颜色
controller.navigationBar.barTintColor=[UIColor greenColor];

设置页面导航控制器的内容

//设置导航栏中间内容
self.navigationItem.title=@"首页";
//设置导航栏右侧按钮
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"右侧" style:UIBarButtonItemStylePlain target:self action:@selector(touchRight)];

设置导航控制器的按钮点击事件

-(void)touchRight{
SecondViewController *second=[[SecondViewController alloc]init];
[self.navigationController pushViewController:second animated:YES];
[self.navigationController popViewControllerAnimated:YES];

}