0
votes

I have implemented a UISplitViewController and all works fine. What I want to do is on iPhone devices only show the detailView not the masterView as the first view controller. I realise I can create a segue from the master view to the detail view in the masters viewDidLoad method however this feels a bit hacky to me. Maybe this is the only way to achieve what I want?

I have looked at the documentation for the UISplitViewControllerDelegate particularly this function however I don't feel I grasped what this actually is doing. I have also set the UISplitViewController as the delegate and set allVisible and tried all the other options in the viewDidLoad of my SplitViewController sub class

self.delegate = self
self.preferredDisplayMode = .allVisible

func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool {
     return true
}

If it helps the detailViewController heirachy in the storyboard is SplitViewController > UINavigationController > myDetailViewController

1

1 Answers

2
votes


What you need to do is to use the splitviewcontroller delegate function
func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool
In there you can push your second controller into your first navigation controller and return true. Returning true means that you're gonna handle the transition. e.g.

func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool { 
if let detailViewController = secondaryViewController as? YourSecondViewController, let primaryNV = primaryViewController as? UINavigationController  {
   primaryNV.pushViewController(detailViewController, animated: false)
   returns true // I handle it myself.
  }
  return false // let the iOS handles it.
}

If you need more clarification, please let me know. I'll try to explain it better. cheers!.