如何确保我的Detail View控制器始终嵌入在UINavigationController中?
我有一个UISplitViewController
有一个preferredDisplayMode = .AllVisible
。 Here是我如何设置故事板,注意详细视图控制器是如何嵌入UINavigationController
中的。如何确保我的Detail View控制器始终嵌入在UINavigationController中?
我执行下面的方法,当一个特定的按钮,在主视图控制器的toolBar
被窃听:
@IBAction func entertainmentBarButtonItemTapped(sender: AnyObject) {
self.showDetailViewController(self.storyboard!.instantiateViewControllerWithIdentifier("SearchViewController") as! SearchViewController, sender: sender)
}
现在这个工作正常在iPhone上的肖像模式,但在横向模式下在iPhone 6 +,我没有看到详细视图控制器(刚刚提供的那个)的navigationBar
。这不是我想要的行为。请注意,默认的“详细视图控制器”嵌入在UINavigationController
中,因此,您可以想象,当navigationBar
突然缺失时,它看起来不一致。
于是我尝试以下方法来代替:
@IBAction func entertainmentBarButtonItemTapped(sender: AnyObject) {
self.showDetailViewController(self.storyboard!.instantiateViewControllerWithIdentifier("NavigationSearchViewController") as! NavigationSearchViewController, sender: sender)
}
现在我像以前那样更换我的详细视图控制器使用相同的VC,但它不是嵌入UINavigationController
。该行为按预期在6+横向模式下工作,因为它显示导航条。
但是在纵向模式下,我看到了故障行为,因为现在当新的VC被推入堆栈时,我看到toolBar
在原始的详细视图控制器上消失,导致一个奇怪的过渡, 。
我该如何正确使用showDetailViewController(..)
,以便始终将我的Detail View Controller嵌入到UINavigationController
中,但没有任何奇怪的转换?我认为这需要我修改UISplitViewController委托,但我一直得到'不能推UINavigationController堆栈。'错误。
编辑: 我修改的唯一代表:
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
}
我目前看到相同的行为。
是,实现委托:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.splitViewController.delegate = self;
...
}
#pragma mark - UISplitViewControllerDelegate
/* On iPhone 6 Plus:
Portrait: This method is called and YES is returned.
Landscape: This method is not called.
On iPad Air
Portrait: This method is not called.
Landscape: This method is not called.
*/
- (BOOL) splitViewController:(UISplitViewController *)splitViewController
collapseSecondaryViewController:(UIViewController *)secondaryViewController
ontoPrimaryViewController:(UIViewController *)primaryViewController
{
if (self.masterNavController.topViewController)
{
return YES;
}
return NO;
}
这个问题可能是你的UISplitViewController委托方法
splitViewController:separateSecondaryViewControllerFromPrimaryViewController:
你没有显示。
我怀疑它是返回detailView控制器而不是包含它的导航控制器。
更新的原文,我不确定masterNavController在您的上下文中。 – AppreciateIt