IOS学习(六)导航视图控制器
来源:互联网 发布:python笔试选择题 编辑:程序博客网 时间:2024/04/29 10:06
Appdelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; [self.window makeKeyAndVisible]; UINavigationController *navigationCtonroller =[[UINavigationController alloc] initWithRootViewController:[[FirstViewController alloc] init]]; [self.window setRootViewController:navigationCtonroller]; return YES;}
FistViewController
- (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor grayColor]; self.title = @"First"; UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:NULL]; //设置系统图片,设置单个view// self.navigationItem.leftBarButtonItem = leftButton; //自定义itembutton UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 90, 30)]; label.text = @"应用商店"; label.backgroundColor = [UIColor grayColor]; UIBarButtonItem *customButton = [[UIBarButtonItem alloc] initWithCustomView:label]; [label targetForAction:@selector(pushController) withSender:self]; //设置多个itmesButton self.navigationItem.leftBarButtonItems = @[leftButton,customButton]; //设置导航控制器的颜色// self.navigationController.navigationBar.backgroundColor = [UIColor redColor]; //设置导航控制器的背景图片// [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"buttonPost"] forBarMetrics:UIBarMetricsDefault]; UIButton *pushButton = [UIButton buttonWithType:UIButtonTypeCustom]; pushButton.frame = CGRectMake(0, 100, 100, 30); pushButton.backgroundColor = [UIColor greenColor]; [pushButton setTitle:@"push" forState:UIControlStateNormal]; [pushButton addTarget:self action:@selector(pushController) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:pushButton];}- (void)pushController { NSLog(@"hehhe"); //这里如果SecondViewController没有设置背景色,没有做其他操作,在跳转时,跳转动画将发生卡顿现象 [self.navigationController pushViewController:[[SecondViewController alloc] init] animated:YES];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}
SecondViewController
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.title = @"Second"; self.view.backgroundColor = [UIColor blueColor]; UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"POP" style:UIBarButtonItemStylePlain target:self action:@selector(pop)]; self.navigationItem.leftBarButtonItem = item; UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"PUSH" style:UIBarButtonItemStylePlain target:self action:@selector(push)]; self.navigationItem.rightBarButtonItem = rightItem; }- (void)push{ [self.navigationController pushViewController:[[ThridViewController alloc] init] animated:YES];}- (void)pop { [self.navigationController popViewControllerAnimated:YES];}
ThirdViewController
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.title = @"Third"; self.view.backgroundColor = [UIColor greenColor]; UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"跳转" style:UIBarButtonItemStylePlain target:self action:@selector(push)]; self.navigationItem.leftBarButtonItem = rightItem; }- (void)push { //跳转到根视图// [self.navigationController popToRootViewControllerAnimated:true]; //销毁当前视图// [self.navigationController popViewControllerAnimated:YES]; //获取导航控制器下所有的视图控制器 NSLog(@"%@", self.navigationController.viewControllers); //跳转到指定视图控制器 [self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];}
0 0
- IOS学习(六)导航视图控制器
- ios学习笔记(六)视图控制器
- IOS开发学习笔记(导航控制器,视图控制器,模态)
- iOS UI07_导航视图控制器
- 导航视图控制器-------------学习笔记
- 导航视图控制器学习笔记
- iOS导航控制器学习笔记(1)
- iOS--项目最常见框架的搭建(标签栏控制器+导航栏控制器+视图控制器)
- IOS开发基础05(导航视图控制器,跳转视图控制器,模态)
- IOS之导航控制器与表视图
- IOS开发-表视图LV3导航控制器
- IOS-导航视图控制器的使用
- iOS学习笔记-003.视图 & 视图控制器
- IOS使用视图控制器和视图(六)使用 UIActivityViewController 显示分享选项
- iOS- 自定义导航控制器(-)
- 导航栏视图控制器(navigation controller)
- 导航视图控制器UINavigationController
- UINavigationController 导航视图控制器
- poj--1703 Find them, Catch them(并查集)
- c语言练习
- docker pull命令实现与镜像存储(1)
- crypt1<uscao>1.3
- 0003算法笔记——【分治法】分治法与二分搜索,棋盘覆盖问题
- IOS学习(六)导航视图控制器
- 递归函数
- Function pointer - 函数指针
- Docker学习笔记 --- Iaas,Paas,SaaS详解
- 启动报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- 数据结构(9)——树
- jQuery ajax的traditional参数的作用
- 设置定时备份数据库的脚本语言
- MSSQL2008 数据库展开报错:值不能为空?(已解决)