My standard implementation for this delegate method is the following. I just initialize the navigation button and save locally the button and the popover.
- (void) splitViewController: (UISplitViewController *) splitController
willHideViewController: (UIViewController *) viewController
withBarButtonItem: (UIBarButtonItem *) barButtonItem
forPopoverController: (UIPopoverController *) popoverController
{
// Set the button to open the PopOver
barButtonItem.title = viewController.title;
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
// Save the ref to the default left navigation button
_masterButton = barButtonItem;
// Save the ref to the PopOver
_masterPopOver = popoverController;
}
From iOS 8 this method is deprecated and the Apple documentation says:
Implement the splitViewController:willChangeToDisplayMode: method instead.
But the arguments of the new method has nothing to do with the deprecated method! I guess I have to create a button and a popover myself?
Does somebody already made this re-coding to implement the current popup behaviour?
Thank you for your help
Take a look at displayModeButtonItem. It is very similar to barButtonItem from the deprecated method.
You can refactor your example into using the new splitViewController:willChangeToDisplayMode: method in the following way:
- (void)splitViewController:(UISplitViewController *)svc
willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode {
if (displayMode == UISplitViewControllerDisplayModePrimaryHidden) {
self.navigationItem.leftBarButtonItem = svc.displayModeButtonItem;
}
}
This is an extension to Alexander's answer. To cover Cihad's comment: the last line of code creates the leftBarButtonItem and makes it the blue "<" button that will open the master viewController.
I just commented out willHideViewController and willShowViewController from my detail viewController and cut and pasted Alexander's code. Worked first time.
Then I discovered that if I started the app in portrait it did not work until I went landscape and back to portrait. Obviously the method is not called until a change of orientation.
So I added this code in my viewDidLoad method of my detail viewController and it worked fine:
//Set up the splitview controller
if (self.splitViewController.displayMode == UISplitViewControllerDisplayModePrimaryHidden) {
self.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;}
splitViewController is a property of your detail viewController that should be there for you to use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With