一,可以用于创建有关联关系的页面
二,UINavigationController
1,UINavigationController维护一个多屏幕的堆栈,每个screen都是一个viewController
2,UINavigationController继承于viewController,它的view属性包含一个UINavigationBar和topViewController的view;
3,可以直接将UINavigationController添加到window中,这样也可以做到UINavigationController的切换
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]]; // Override point for customization after application launch BNRItemsViewController *itemsViewController = [[BNRItemsViewController alloc] init]; // Create an instance of a UINavigationController // its stack contains only itemsViewController UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:itemsViewController]; self.window.rootViewController = itemsViewController; // Place navigation controller's view in the window hierarchy self.window.rootViewController = navController; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; }
四,使用UINavigationController进行页面导航
1,初始化UINavigationController必须有一个controller
2,可以使用controller的navigationController访问UINavigationController
3,可以使用navigationController的pushViewController:animated:添加一个controller
4,所有加入到navigationController的controller构成一个堆栈关系
五,在controller之间传递数据
1,可以直接在controller之间传递数据
2,一般可以将数据都放在root controller中,并传递到下一级的controller
六,隐藏或显示views
1,使用[self.view endEditing:YES];来释放focus,并隐藏键盘
2,使用self.tableView reloadData来刷新tableView的显示
七,UINavigationBar
1,UIViewController有一个UINavigationItem的属性,navigationController使用它来初始化导航条
2,手动创建action连接
- (instancetype)init { self = [super initWithStyle:UITableViewStylePlain]; if (self) { UINavigationItem *navItem = self.navigationItem; navItem.title = @"Homepwner"; // Create a new bar button item that will send // addNewItem: to BNRItemsViewController UIBarButtonItem *bbi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addNewItem:)]; // Set this bar button item as the right item in the navigationItem navItem.rightBarButtonItem = bbi; } return self; }
3,连接编辑模式
navItem.leftBarButtonItem = self.editButtonItem;
viewController访问editButtonItem时候,会创建并返回UIBarButtonItem
4,UINavigationItem不是一个view