Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Instead of modifying the <code>MGSplitViewController</code> source or subclassing it, you can use the <code>showsMasterInPortrait</code> property of the <code>MGSplitViewController</code> to toggle the master on and off from your application code. This has always worked fine for me.</p> <p><strong>Update with specifics:</strong></p> <p>I wouldn't use the bar button item that the split view controller provides - it's not overly useful for our purposes. Instead, set up your own button, with an associated action which toggles the <code>showsMasterInPortrait</code> property of your split view controller. To get to the latter, wire up an outlet property. You'll also need an outlet for the button itself if you're going to hide the button in landscape. Make sure that's wired up correctly in IB, too.</p> <p>In the header, that means something like this:</p> <pre><code>@property(nonatomic,assign) IBOutlet MGSplitViewController* splitVC; @property(nonatomic,assign) IBOutlet UIBarButtonItem* toggleButton; - (IBAction)toggleMasterViewTouched:(id)sender; </code></pre> <p>And in the class definition:</p> <pre><code>@synthesize splitVC, toggleButton; - (IBAction)toggleMasterViewTouched:(id)sender { BOOL master_shown = !self.splitVC.showsMasterInPortrait; // Note: toggle the button's label text and/or icon between "hide" and "show" versions self.toggleButton.title = master_shown ? @"Hide Master" : @"Show Master"; self.splitVC.showsMasterInPortrait = master_shown; } </code></pre> <p>If you only want the button to appear in portrait, you'll also need to hide it on autorotation, so respond to the rotation event (still in the detail controller):</p> <pre><code>- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { // hide when in landscape, show when in portrait self.toggleButton.hidden = UIInterfaceOrientationIsLandscape(toInterfaceOrientation); } </code></pre> <p>And that should hopefully be all. You'll also want to set up defaults for showsMasterInPortrait and the toggle button label and visibility somewhere, probably in <code>viewDidLoad</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload