We implemented UISplitViewController
without using storyboard. Our split view controller consists of master and detail controllers, both individually wrapped within UINavigationController
. We configured split view controller with following:
- set propery
preferredDisplayMode = .allVisible
func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool { return false }
With such settings, we expect that iPads will have both, master and detail controllers visible in portrait and also landscape. That works just fine. For iPhones, we expect it to behave like a regular Navigation controller, so that master (in our case table) will be displayed first with possible transitions to detail screen and back (using navigation bar). For transition master->detail, we call split view controller's method: showDetailViewController(detailNavigationController)
. With such implementation, we get a weird behavior when detail screen is not extended full screen even though we set it so. For some reason, there is an empty space on top and bottom of the screen as well. We figured its caused by the "extra" navigation controller that wraps the detail controller. So, whenever we do transition master->detail we do different calls for iPads and iPhones:
if isiPad() {
showDetailViewController(UINavigationController(rootViewController: detailController, sender: self)
} else if isiPhone() {
showDetailViewController(detailViewController, sender: self)
}
This "works" for us at the moment, but we would obviously like to replace it with cleaner solution.