【iOS基础控件 - 15】- UINavigationController 多控制器 简单使用
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了【iOS基础控件 - 15】- UINavigationController 多控制器 简单使用,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含7190字,纯文字阅读大概需要11分钟。
内容图文
![【iOS基础控件 - 15】- UINavigationController 多控制器 简单使用](/upload/InfoBanner/zyjiaocheng/1315/75bafa3adbd647d985e773cd4a44f4ce.jpg)
- UINavigationController
- UITabBarController
初始化UINavigationController
设置UIWindow的rootViewController为UINavigationController
1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 2 // 设置window 3 self.window = [[UIWindow alloc] init]; 4 self.window.frame = [[UIScreen mainScreen] bounds]; 5 self.window.backgroundColor = [UIColor grayColor]; // window是灰色背景 6 [self.window makeKeyAndVisible]; 7 8 9 // 设置UINavigationController 10 UINavigationController *nvController = [[UINavigationController alloc] init]; 11 nvController.view.backgroundColor = [UIColor blueColor]; // 设置蓝色背景 12 self.window.rootViewController = nvController; 13 14 return YES; 15 }
1 // 配置第一个子控制器 2 ViewControllerOne *vc1 = [[ViewControllerOne alloc] init]; 3 [nvController pushViewController:vc1 animated:YES]; 4 5 // 配置第二个子控制器 6 ViewControllerTwo *vc2 = [[ViewControllerTwo alloc] init]; 7 [nvController pushViewController:vc2 animated:YES]; 8 9 // 配置第三个子控制器,这是栈顶的控制器 10 ViewControllerThree *vc3 = [[ViewControllerThree alloc] init]; 11 [nvController pushViewController:vc3 animated:YES];
1 - (void)applicationDidBecomeActive:(UIApplication *)application { 2 // 必须在加载完毕激活app后,所有的view的尺寸位置才能确定 3 UINavigationController *nvController = (UINavigationController *)self.window.rootViewController; 4 NSLog(@"%@", NSStringFromCGRect(nvController.view.frame)); // 整个导航控制器的frame 5 NSLog(@"%@", NSStringFromCGRect(nvController.navigationBar.frame)); // 导航条的frame 6 } 7
1 @property(nonatomic,copy) NSArray *viewControllers; // The current view controller stack.
1 - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; // Uses a horizontal slide transition. Has no effect if the view controller is already in the stack.
1 // 配置第一个子控制器 2 ViewControllerOne *vc1 = [[ViewControllerOne alloc] init]; 3 [nvController pushViewController:vc1 animated:YES];
- UINavigationController中的”viewControllers"成员是一个数组,就是子控制器栈
- "childViewControllers"的功能也是一样的(这是UIViewController的成员属性)
- "addChildController"和"pushViewController"的功能一样(这是UIViewController的方法)
1 ViewControllerOne *vc1 = [[ViewControllerOne alloc] init]; 2 [nvController addChildViewController:vc1];
1 // 配置第一个子控制器 2 ViewControllerOne *vc1 = [[ViewControllerOne alloc] init]; 3 nvController.viewControllers = @[vc1];
1 // 传入一个viewController作为 nvController的 rootViewController 2 nvController = [[UINavigationController alloc] initWithRootViewController:vc1];
1 - (IBAction)goToThree { 2 // 配置第三个子控制器 3 ViewControllerThree *vc3 = [[ViewControllerThree alloc] init]; 4 [self.navigationController pushViewController:vc3 animated:YES]; 5 } 6 7 - (IBAction)gotoFour { 8 // 配置第四个子控制器 9 ViewControllerFour *vc4 = [[ViewControllerFour alloc] init]; 10 [self.navigationController pushViewController:vc4 animated:YES]; 11 }
1 // 这里是第三个,要回到第二个 2 - (IBAction)backtoTwo { 3 [self.navigationController popViewControllerAnimated:YES]; 4 }
1 @property(nonatomic,copy) NSString *title; // Localized title for use by a parent controller.
1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 self.navigationItem.title = @"第一个view"; 4 }
1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 self.navigationItem.title = @"第二个控制器"; 4 5 // 设置左上角的item 6 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"我要回去" style:UIBarButtonItemStylePlain target:nil action:nil]; 7 8 // 设置右上角的item 9 // 使用bar按钮 10 UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:nil action:nil]; 11 12 // 使用自定义view 13 UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithCustomView:[UIButton buttonWithType:UIButtonTypeContactAdd]]; 14 15 // 这是这是从右到左排列显示 16 self.navigationItem.rightBarButtonItems = @[item1,item2]; 17 }
1 - (void)applicationDidBecomeActive:(UIApplication *)application { 2 // 必须在加载完毕激活app后,所有的view的尺寸位置才能确定 3 UINavigationController *nvController = (UINavigationController *)self.window.rootViewController; 4 NSLog(@"%@", NSStringFromCGRect(nvController.view.frame)); // 整个导航控制器的frame 5 NSLog(@"%@", NSStringFromCGRect(nvController.navigationBar.frame)); // 导航条的frame 6 }
最后的点击链接图:
原文:http://www.cnblogs.com/kengsir/p/4281913.html
内容总结
以上是互联网集市为您收集整理的【iOS基础控件 - 15】- UINavigationController 多控制器 简单使用全部内容,希望文章能够帮你解决【iOS基础控件 - 15】- UINavigationController 多控制器 简单使用所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。