Hiding Master View Controller in SplitView regardless of device orientation

10,318

You actually have no control over a UISplitViewController. The master view is always present in landscape view, and there is no possible way of changing this.

However, "Matt Gemmell created an excellent custom splitViewController called 'MGSplitViewController'. It is very easily implemented, heavily commented, and contains a lot of excellent features not found with a normal splitViewController (hide master view on landscape view, change placement of the split in landscape view, allow user to change size of split fluidly during runtime, etc)."

Info and demo: http://mattgemmell.com/2010/08/03/mgsplitviewcontroller-updated/

Straight to the source: https://github.com/mattgemmell/MGSplitViewController/

-=-=-=-=-=-=-=-=-=-=-=-

I've posted this before in a similar (but different) question with the same answer here:

How to hide master view in UiSplitviewcontroller in ipad

-=-=-=-=-=-=-=-=-=-=-=-

UPDATE:

In iOS 5.0 and beyond, they have finally added functionality to hide master view in landscape!

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

Reference: splitViewController in Ipad that doesnt hide in portrait

Share:
10,318
Hrafn
Author by

Hrafn

Coffee & code. Mostly coffee.

Updated on June 04, 2022

Comments

  • Hrafn
    Hrafn almost 2 years

    I've found lots of people asking for information on how to have the Master view displayed both in landscape and portrait orientation, but what I am trying to do is to having the right master view hidden regardless of the devices orientation and popping in from the side by using a navbar button.

    What would help me enormously would be if someone could tell me where the logic for hiding the master view is located/executed when the device reorients. I've been looking at the template that comes with Xcode, Master/detail view for iOS, and I noticed these two following methods are declared in the AppDelegate.m file but I can't seem to find out where they are being executed from:

    //Called when a button should be added to the nav bar for a view that is hidden
    - (void)splitViewController:(UISplitViewController *)splitController willHideViewController: (UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
    {
       barButtonItem.title = NSLocalizedString(@"Master", @"Master");
       [self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
       self.masterPopoverController = popoverController;
    }
    
    - (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
    {
        // Called when the view is shown again in the split view, invalidating the button and popover controller.
        [self.navigationItem setLeftBarButtonItem:nil animated:YES];
        self.masterPopoverController = nil;
    }
    

    All help would be appreciated.

  • Hrafn
    Hrafn almost 12 years
    Thank you for the answer, and the links. Will definitely check it out.
  • Highrule
    Highrule almost 12 years
    Sure no problem. Also, it seems that just recently in iOS 5.0 they added functionality to do just what you're looking for! Though MGSplitViewController does have a lot of great extra functionality, this could be the simple fix you're looking for. @MrDresden
  • Kyle
    Kyle over 11 years
    Is there a way to unhide the view controller once you've hidden it? I cant seem to find a way to get this function called again
  • palaniraja
    palaniraja almost 11 years
    @Kyle did you find solution?