Search code examples
iosuisplitviewcontrollerios9

UISplitViewController + Split View: hide details at startup


I have a UISplitViewController in an iPad app and until now I was setting a placeholder as the details view controller at startup, so the right part of the screen would not look empty until the user selects an item.

But now, on iOS 9, when using a 50/50 horizontal Split View (multitasking), the split view controller automatically pushes my placeholder, when of course I would like it to show the master view because in that case the placeholder is not needed.

Does anybody know how to avoid this automatic behavior?

Maybe there is a piece of API that does just that, and I missed it? Something like 'selectViewController:' to tell the split view controller to show the master view or the detail view. Or maybe we can access the internal navigation controller so we pop to root?

Thanks!


Solution

  • You need to implement the UISplitViewControllerDelegate method

    - (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController
    

    According to the documentation, this method's return value is:

    NO to let the split view controller try and incorporate the secondary view controller’s content into the collapsed interface or YES to indicate that you do not want the split view controller to do anything with the secondary view controller.

    Implementing this delegate method and returning YES should make the split view controller display the master view controller at startup.