Search code examples
iosobjective-cxcodeuisplitviewcontroller

UISplitView using Storyboard in Universal iOS app


I am using UISplitView in my universal iOS application and I have one storyboard only. I am able to implement all functionality except few things,

In iPad I want master view to be visible always hence I used the delegate,

-(BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
    return NO;
}

But still the master view is hiding in Portrait mode. Also in iPhone the application launches with DetailView with navigation back button. I want the iPhone application to display MasterView first. I have gone through several samples like this, or this, but nothing solved my issue.

I am using Objective C not Swift.


Solution

  • Have a look at the documentation for UISplitViewControllerDelegate

    - (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
    

    has been deprecated in iOS8, you have to set the preferredDisplayMode instead:

    controller.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
    

    As for the iPhone app displaying the detail view controller instead of the master, implement the UISplitViewControllerDelegate method:

    - (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController {
        return YES;
    }