I have a master detail iPad interface set up with storyboard to provide a replace segue on the detail view controller. This works fine to replace the detail controller, however the bar button to display the master controller is missing in certain situations.
If I do the segue while in portrait, the bar button is missing because the willHideViewController:
delegate method is never called. I am setting the delegate to the new detail controller when prepareForSegue:
is called from the master.
When the button is missing, I can rotate the iPad to landscape then back to portrait and the button will then appear.
In prepareForSegue:
UINavigationController *nav = [segue destinationViewController];
UIViewController *destinationViewController = nav.topViewController;
if ([destinationViewController conformsToProtocol:@protocol(UISplitViewControllerDelegate)]) {
self.splitViewController.delegate = destinationViewController;
}
else {
self.splitViewController.delegate = nil;
}
In the detail controllers:
#pragma mark - Split view
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
barButtonItem.title = NSLocalizedString(@"MasterButton", @"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;
}