我对如何在6 Plus以外的iPhone上处理拆分视图控制器感到困惑,因为6 Plus可以处理iPad等拆分视图控制器。我希望明细视图控制器成为那些iPhone上出现的根视图控制器。
编辑
通过添加这两个委托方法,我可以获得所需的行为。现在,拆分视图控制器折叠为详细信息视图控制器,而不是iPhone上的主视图控制器。
- (UIViewController *)primaryViewControllerForCollapsingSplitViewController:(UISplitViewController *)splitViewController
{
return self.detailNavigationController;
}
- (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController
{
return YES;
}
问题1
当我将主视图控制器推到iPhone上的详细视图控制器的导航控制器上时,我正在控制台中收到此消息。它工作正常,所以我不明白为什么收到此消息。
Unbalanced calls to begin/end appearance transitions for <MasterTableViewController: 0x7fc8d2b67220>.
问题2
我尚不清楚检测分割视图控制器何时在iPhone上崩溃的首选方法。我正在使用
UIViewControllerShowDetailTargetDidChangeNotification
通知来检测此更改,但我觉得应该为此更改提供某种委托方法。 最佳答案
如果您使用默认模板创建了UISplitViewController,则可以在AppDelegate文件中找到此方法。
- (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController {
if ([secondaryViewController isKindOfClass:[UINavigationController class]] && [[(UINavigationController *)secondaryViewController topViewController] isKindOfClass:[DetailViewController class]] && ([(DetailViewController *)[(UINavigationController *)secondaryViewController topViewController] detailItem] == nil)) {
// Return YES to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded.
return YES;
} else {
return NO;
}
}
当返回YES时,此方法处理小屏幕设备中UISplitViewController的默认行为,要解决您的问题,您必须返回NO。用下面的代码替换该方法
- (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController {
if ([secondaryViewController isKindOfClass:[UINavigationController class]] && [[(UINavigationController *)secondaryViewController topViewController] isKindOfClass:[DetailViewController class]] && ([(DetailViewController *)[(UINavigationController *)secondaryViewController topViewController] detailItem] == nil)) {
// Return YES to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded.
return NO;
} else {
return NO;
}
}
看看documentation