第一.UINavigationController的基本概念
UINavigationController是用于构建分层应用程序的主要工具,管理者多个内容视图的换入和换出,自身提供了切换的动画效果.
第二.基本样式
主要三部分:
1.导航栏:NavigationBar,在最上面,主要负责视图的弹出和控制主视图,高度是44px/32px(横过来),上面的logo是20*20px
2.内容视图,中间部分,用于显示内容
3.工具栏(UIToolBar),默认是隐藏的,用户可以自己添加工具栏,高度是44px/32px(横过来)
第三、示例代码:
RootViewController *rootViewController=[[[RootViewController alloc] init] autorelease];
NSLog(@"the first controller is %@",rootViewController.navigationController);
UINavigationController *controller=[[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease];
NSLog(@"the end controller is %@",rootViewController.navigationController);
输出结果是:
2013-09-10 19:21:13.236 simpleNavigation[1841:c07] the first controller is (null)
2013-09-10 19:21:13.239 simpleNavigation[1841:c07] the end controller is <UINavigationController: 0x892eb70>
分析: UINavigationController *controller=[[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease];
rootViewController的navigatoncontroller为空,在执行了该语句之后navigationcontroller就有值了
[self.navigationControllerpushViewController:secondVCanimated:YES];就可以实现跳转了
[self.navigationControllersetToolbarHidden:NOanimated:YES]; //设置Toolbar是否显示
[self.navigationControllersetNavigationBarHidden:NO]; //设置导航栏是否显示
第三UINavagitionController的代理,通过设置代理监听视图控制器的切换