iOS-iPad开发之SplitViewController简单介绍
SplitViewController图形化创建
SplitViewController可以并列显示两个view,适用于基于navigation导航的和“主-从”视图。“主-从”视图分别为masterViewCotroller, detailViewController.
- masterViewCotroller 在视图左边, 负责建立逻辑关系.
- detailViewController 在视图右边, 负责显示具体内容, 完成交互操作
SplitViewController代码创建
//子视图
MasterViewController *control1 = [[MasterViewController alloc]init];
DetailViewController *control2 = [[DetailViewController alloc]init];
control1.detailVC = control2;
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:control2];
nav2.navigationBar.translucent = NO;
//分页视图
self.SplitVC = [[UISplitViewController alloc]init];
self.SplitVC.delegate = control2;//设置代理
self.SplitVC.viewControllers = @[control1, nav2];//建立联系
//添加到视图
self.window.rootViewController = self.SplitVC;
改变detailViewController内容
将DetailViewController作为MasterViewController的一个属性,设置联系. 之后,就可以通过这个属性,在maserViewController中设置detailViewController的内容了.
self.detailVC.label.text = [NSString stringWithFormat:@"cell%ld", indexPath.row];
[self.detailVC.view setNeedsLayout];
设置分页视图控制按钮
分页视图控制按钮, 点击该按钮, 触发指定功能.
获取方法:
//分页视图按钮
UIBarButtonItem *item = [self.splitViewController displayModeButtonItem];
指定功能设置:
//此方法为UISplitViewControllerDelegate中方法
- (UISplitViewControllerDisplayMode)targetDisplayModeForActionInSplitViewController:(UISplitViewController *)svc{
return UISplitViewControllerDisplayModeAutomatic;
}