I have a UISplitViewController that has a preferredDisplayMode = .AllVisible . Here is how I have set up my storyboard, notice how the Detail View Controller is already embedded in a UINavigationController.
I execute the following method when a specific button is tapped in the toolBar of the Master View Controller:
@IBAction func entertainmentBarButtonItemTapped(sender: AnyObject) {
self.showDetailViewController(self.storyboard!.instantiateViewControllerWithIdentifier("SearchViewController") as! SearchViewController, sender: sender)
}
Now this works fine on an iPhone in portrait mode, but in landscape mode on an iPhone 6+, I see no navigationBar for the Detail View Controller (the one just presented). This is not the behavior I desire. Note that the default Detail View Controller is embedded in a UINavigationController, so as you can imagine, it looks inconsistent when the navigationBar is suddenly missing.
So then I try the following instead:
@IBAction func entertainmentBarButtonItemTapped(sender: AnyObject) {
self.showDetailViewController(self.storyboard!.instantiateViewControllerWithIdentifier("NavigationSearchViewController") as! NavigationSearchViewController, sender: sender)
}
Now I am replacing my Detail View Controller with the same VC as before, but it is instead embedded in a UINavigationController. The behavior works as expected on a 6+ in landscape mode, since it shows the navigationBar.
But in portrait mode, I see glitched behaviour, because now as the new VC is pushed to the stack, I see the toolBar disappear on the original Detail View Controller, causing a weird transition where clearly something didn't go right.
How can I properly use showDetailViewController(..) so that I always have my Detail View Controller embedded in a UINavigationController but without any odd transitions? I think this requires me to modify the UISplitViewController delegates, but I keep getting a 'Cannot push UINavigationController to stack.' error.
Edit: The only delegate I modified:
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
}
I currently see the same behavior.
The problem is probably your UISplitViewController delegate method
splitViewController:separateSecondaryViewControllerFromPrimaryViewController:
which you didn't show.
I suspect that it is returning the detailView controller rather than the navigation controller that contains it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With