每当我尝试以模态方式呈现 UISplitViewController 时,应用程序就会崩溃。因此它必须始终是根视图控制器。谁能证实这一点?
5 回答
拆分视图控制器的视图应始终安装为应用程序窗口的根视图。您永远不应该在导航或标签栏界面内显示拆分视图。
所以是的,您不能在主应用程序窗口(包括模态)之外显示拆分视图。
编辑
上面文档的链接不再讨论这个话题。现在可以在 Apple 的iOS 视图控制器目录中找到相关讨论,其中指出:
拆分视图控制器必须始终是您创建的任何界面的根。换句话说,您必须始终将 UISplitViewController 对象中的视图安装为应用程序窗口的根视图。[...] 拆分视图控制器不能以模态方式呈现。
I got the same problem with the same error when I tried to segue from a regular content view controller (ie. no problem segueing from a tab controller or a nav controller).
Fortunately I found a way to circumvent this by inserting a nav controller between the VC and the split view controller. In other word, segue from the VC to a nav controller, then draw a relationship connection between the nav controller and the split view controller. In this way, instantiating a split view still requires no coding.
当然你可以UISplitViewController
不使用它作为根视图控制器来使用它。在我的项目中,我这样使用它:
- 以模态方法显示我自己的视图控制器:
[自我presentModalViewController:mainViewController动画:YES];
- 在 mainViewController 中,我有
UISplitViewController *splitViewController;
在 中- (void)viewDidLoad
,设置splitViewController.view
为mainViewController.view
splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
self.view = splitViewController.view;
UISplitController 可以安装在 UITabBarController 下。我做。只需在这个论坛上使用搜索 - 我找到了至少一个好的软件示例。
是的,你必须使用 RootViewController,它应该继承自 UITableViewController。你可以看看这个教程