参考的链接:
http://nshipster.cn/uisplitviewcontroller/
http://coding.tabasoft.it/ios/the-new-uisplitviewcontroller/
iPhone刚打开时,只显示detail,如果要让它先显示master,需要实现UISplitViewControllerDelegate的方法
- (void)viewDidLoad {
[super viewDidLoad];
self.splitViewController.delegate = self;
}
- (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController {
return YES;
}
iPad Portrait刚启动时,只显示detail,需要向右滑动才能显示master
没有任何提示相当不友好,可以在导航栏上加上一个返回的按钮,UISplitViewController 有一个 displayModeButtonItem,可以被添加到导航栏:
self.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
self.navigationItem.leftItemsSupplementBackButton = YES;
当SplitViewController折叠只显示master时(iPhone),它的viewControllers只有一个master,用viewControllers[1]来获取detail会越界
在ios8以前,我们显示一个新的detail的VC实在这样做的
PhotoViewController *photoVC = (PhotoViewController*)self.splitViewController.viewControllers[1];
photoVC.image = image;
在ios8以后,我们是这样做的
PhotoViewController *photoVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"photovc"];
self.showDetailViewController(photoVC, sender: self)
最大的区别在于,在ios8我们需要实例化一个全新的detail VC,而不是简单地替换当前的detail VC。