Reputation: 172
I am trying to preserve the functionality of iOS 13 and UISplitViewController in my app for iOS 14. Everything works as intended (two side by side view controllers) in landscape mode, but if I launch the app (the split view controller is the initial view controller) in portrait, my conditional logic to show the primary view controller when a variable in the detail view controller is nil is not functioning properly AND the navigation bar (bar button items, large titles) for the primary and detail view controller is not visible.
func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool {
if (secondaryViewController is UINavigationController) && (((secondaryViewController as? UINavigationController)?.topViewController) is DetailViewController) && (((secondaryViewController as? UINavigationController)?.topViewController as? DetailViewController)?.dict == nil) {
return true
} else {
return false
}
}
Strangely enough, if I launch the app in landscape and then move to portrait, the titles are there, the bars are there, and everything works as intended. This seems to be an issue with first launch in portrait mode.
Upvotes: 1
Views: 1341
Reputation: 172
The solution is to use the new delegate method topColumnForCollapsingToProposedTopColumn
and return .primary
or .secondary
as needed.
Upvotes: 3
Reputation: 31
I found another way to accomplish this:
Main.storyboard
SplitViewController
compact view
" to your desired view controller.For me, this means I now have 2 relationships going from the SplitViewController
to my Primary View Controller (2 relationship segues: "master view controller" and "compact view controller"). But, hey it works now. None of the delegate stuff was working for me no matter what I tried.
At the end of the day it seems like the Split View Controller has a property for which view controller is displayed in compact mode. You can set this in your storyboard, and that will determine which view is displayed in compact screens.
Upvotes: 1