Search code examples
ipadios5uiviewcontrolleruisplitviewcontrolleruistoryboard

Hiding a Master View Controller when Selection is Made with Xcode 4.3.2 Storyboards


I want to hide the master view controller when a cell is selected only when the iPad is in portrait view. So the user will click the cell and then the master view controller will go away (like in Mail). Where and how would I do this?

enter image description here

This project is open source: https://github.com/kirkouimet/enzyme


Solution

  • Once you configure your detail view controller, you need to dismiss the popover controller.

    if (self.popoverController) {
        [self.popoverController dismissPopoverAnimated:YES];
    }
    

    If your detail view controller doesn't already have a property to hold the UIPopoverController, you can capture it by implementing these delegate methods for UISplitViewControllerDelegate

    - (void)splitViewController:(UISplitViewController *)iSplitViewController
         willHideViewController:(UIViewController *)iViewController
              withBarButtonItem:(UIBarButtonItem *)iBarButtonItem
           forPopoverController:(UIPopoverController *)iPopoverController {
    
        self.popoverController = iPopoverController;
    }
    
    
    - (void)splitViewController:(UISplitViewController *)iSplitViewController
         willShowViewController:(UIViewController *)iViewController
      invalidatingBarButtonItem:(UIBarButtonItem *)iBarButtonItem {
    
        self.popoverController = nil;
    }