iOS编程第四版第10章 UINavigationController

来源:互联网 发布:淘宝贪吃飒 编辑:程序博客网 时间:2024/05/21 08:02

本章讲述内容如题。

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

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



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

MVC关系如下图:


实例步骤:

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

196- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(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 *)tableViewdidSelectRowAtIndexPath:(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
原创粉丝点击