if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UISplitViewController *splitViewController = (UISplitViewController *)[[tabBarController viewControllers] firstObject];
UINavigationController *navigationController = [[splitViewController viewControllers] lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
}
这是我当前用于检查设备是否为 iPad 的代码。如果是,它应该设置 tabbarcontroller 的第一个对象的最后一个对象的唯一 View Controller 。 Storyboard如下:
Tabbarcontroller[0]>Splitviewcontroller[1]>Navigationcontroller[0]>delegate(?)
我仍然不知道委托(delegate)的作用,但在检查苹果的 Split View Controller 模板代码后,我认为它使用委托(delegate)来通知详细 View Controller 更新内容。我崩溃的行是 [splitViewController viewControllers]
最佳答案
根据 Apple 指南 UISplitViewController
应该是 Root View Controller i。 e.它不能作为子 Controller 插入到 UITabBarController
中:
A split view controller must always be the root of any interface you create. In other words, you must always install the view from a UISplitViewController object as the root view of your application’s window.
来自“View Controller Catalog for iOS”用户指南
关于ios - UITabBarController 中的 UISplitViewController 在尝试检查 [splitViewController viewControllers] 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21138419/