我有一个 UISplitViewController
,它有一个 preferredDisplayMode = .AllVisible
。 Here这就是我设置 Storyboard的方式,请注意细节 View Controller 是如何嵌入到 UINavigationController
中的。
当点击主视图 Controller 的 toolBar
中的特定按钮时,我执行以下方法:
@IBAction func entertainmentBarButtonItemTapped(sender: AnyObject) {
self.showDetailViewController(self.storyboard!.instantiateViewControllerWithIdentifier("SearchViewController") as! SearchViewController, sender: sender)
}
现在这在纵向模式的 iPhone 上运行良好,但在 iPhone 6+ 的横向模式下,我看不到详细 View Controller (刚刚显示的那个)的 navigationBar
。这不是我想要的行为。请注意,默认的 Detail View Controller 嵌入在 UINavigationController
中,因此您可以想象,当 navigationBar
突然丢失时,它看起来不一致。
然后我尝试以下方法:
@IBAction func entertainmentBarButtonItemTapped(sender: AnyObject) {
self.showDetailViewController(self.storyboard!.instantiateViewControllerWithIdentifier("NavigationSearchViewController") as! NavigationSearchViewController, sender: sender)
}
现在我用与以前相同的 VC 替换我的 Detail View Controller,但它嵌入在 UINavigationController
中。该行为在横向模式下的 6+ 上按预期工作,因为它显示了导航栏。
但在纵向模式下,我看到了故障行为,因为现在当新的 VC 被插入堆栈时,我看到 toolBar
在原始的 Detail View Controller 上消失了,导致了一个奇怪的转换,很明显有些事情不对劲。
如何正确使用 showDetailViewController(..)
以便我始终将详细 View Controller 嵌入到 UINavigationController
中,但没有任何奇怪的转换?我认为这需要我修改 UISplitViewController 委托(delegate),但我一直收到“无法将 UINavigationController 插入堆栈”。错误。
编辑: 我修改的唯一委托(delegate):
func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController: UIViewController, ontoPrimaryViewController primaryViewController: UIViewController) -> Bool {
//Since splitViewController!.showViewController changes secondaryViewController to no longer be a UINavigationController, this must first be checked for there to even be a BlankVC.
if let secondaryNavController = secondaryViewController as? UINavigationController {
if ((secondaryNavController.topViewController) != nil) {
return true
}
return false
}
我目前看到了相同的行为。
最佳答案
问题可能出在你的 UISplitViewController 委托(delegate)方法上
splitViewController:separateSecondaryViewControllerFromPrimaryViewController:
你没有展示。
我怀疑它返回的是 detailView Controller 而不是包含它的导航 Controller 。
关于ios - 如何确保我的详细信息 View Controller 始终嵌入到 UINavigationController 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36844863/