iOS编程第四版第10章 UINavigationController

本章讲述内容如题。

类似于window,UINavigationController也有一个root view controller 

在最上层的controller中的view会被显示出来。



它包含一个root view controller, 一个topviewcontroller和一个UINavigationBar

MVC关系如下图:


实例步骤:

1. 创建UINavigationController 实例,并把它设为window的root controller

196
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
<span style="white-space:pre">	</span>self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]];
<span style="white-space:pre">	</span>// Override point for customization after application launch
<span style="white-space:pre">	</span>BNRItemsViewController *itemsViewController = [[BNRItemsViewController alloc] init];
<span style="white-space:pre">	</span>// Create an instance of a UINavigationController
<span style="white-space:pre">	</span>// its stack contains only itemsViewController
<span style="white-space:pre">	</span>UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:itemsViewController];
<span style="white-space:pre">	</span>self.window.rootViewController = itemsViewController;
<span style="white-space:pre">	</span>// Place navigation controller's view in the window hierarchy
<span style="white-space:pre">	</span>self.window.rootViewController = navController;
<span style="white-space:pre">	</span>self.window.backgroundColor = [UIColor whiteColor];
<span style="white-space:pre">	</span>[self.window makeKeyAndVisible];
<span style="white-space:pre">	</span>return YES;
}

2. 添加一个UIViewController作为第二个页面,同时创建其xib文件

3. 添加控件并绑定到自己的controller

4. pushing view controller

5. 在tableviewcontroller中,

- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
<span style="white-space:pre">	</span>BNRDetailViewController *detailViewController = [[BNRDetailViewController alloc] init];
<span style="white-space:pre">	</span>// Push it onto the top of the navigation controller's stack
<span style="white-space:pre">	</span>[self.navigationController pushViewController:detailViewController animated:YES];
}

6. 页面之间数据传递

在UIViewController的viewWillAppear中绑定数据,viewWillDisappear中回写数据。


源码:https://github.com/ianzhengnan/Homepwner





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值