【发布时间】:2015-11-24 08:35:07
【问题描述】:
我几天来一直在努力解决这个问题,但无法让它发挥作用。阅读多个 SO 帖子(this、this、this、this、this 和 this)。问了我的朋友谷歌,帮助理解了问题,但还没有解决。
在我的 iOS 应用程序的第一个版本(Swift2 和 XCode7)中,我使用 UITableViewController 和 UINavigationViewController 从不同的 UIStoryboard 加载新内容。这一切都很好。对于这个应用程序的第二个版本,我想实现一个 UISplitViewController,现在我得到了错误:
*** 由于未捕获的异常“UIViewControllerHierarchyInconsistency”而终止应用程序,原因:“将根视图控制器添加为视图控制器的子级:
我理解提示,但无法以在纵向和横向模式下均有效的方式解决它。此外,我没有在横向使用 UINavigationController 的那种解决方案。
我创建了一个测试项目来追踪这个错误,希望能够解决它。
这是产生错误的代码:
let storyboard = UIStoryboard(name: "ThirdScreen", bundle: nil)
let controller = storyboard.instantiateInitialViewController() as! ThirdDetailViewController
controller.title = "Miracle!"
splitViewController?.showDetailViewController(controller, sender: nil)
这个测试项目的完整代码是available from GitHub。
我怎样才能做到这一点?
非常感谢!
【问题讨论】:
标签: xcode swift uisplitviewcontroller