3

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
  • 2,867
  • 3
  • 25
  • 44

1 Answers1

9

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

Community
  • 1
  • 1
Highrule
  • 1,915
  • 3
  • 19
  • 23
  • Thank you for the answer, and the links. Will definitely check it out. – Hrafn Jun 20 '12 at 09:21
  • 1
    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 – Highrule Jun 20 '12 at 16:01
  • 1
    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 – Kyle Oct 08 '12 at 20:27
  • @Kyle did you find solution? – palaniraja May 10 '13 at 14:39