I'm presenting a modal view controller in a UISplitViewController
based app. I've swapped the default detail view for a UINavigationController
.
In my UINavigationController
, I've implemented some methods to show the "Master" button for the split view controller in the top left. The problem is that when the device orientation changes while the modal view is visible, the button does not disappear from the main view in my navigation controller.
What could be causing this issue?
EDIT:
I've moved the template logic for the button into a subclass of UINavigationController. The problem is that when the visibleViewController presents a modalViewcontroller
, it becomes the visibleViewController
. So, my code won't correctly remove the button for some reason. Here's my code:
Code:
#pragma mark - Split view support
- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController: (UIPopoverController *)pc{
barButtonItem.title = NSLocalizedString(@"Menu", @"");
//
// TODO: Handle cases where there is
// a modal view controller that is
// being shown to the user.
//
[((UIViewController *)[self.viewControllers objectAtIndex:0]).navigationItem setLeftBarButtonItem:barButtonItem];
self.popoverController = pc;
}
// Called when the view is shown again in the split view, invalidating the button and popover controller.
- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem{
[self.visibleViewController.navigationItem setLeftBarButtonItem:nil];
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController = nil;
}
//
// Preserve navigation items across detail
// view loads in portrait mode.
//
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated{
UIBarButtonItem *barItem = nil;
if (self.visibleViewController.navigationItem.leftBarButtonItem != nil) {
barItem = self.visibleViewController.navigationItem.leftBarButtonItem开发者_StackOverflow中文版;
}
[super setViewControllers:viewControllers animated:animated];
if (barItem != nil) {
[self.visibleViewController.navigationItem setLeftBarButtonItem:barItem];
}
}
I don't think it's possible to use SplitViewController and display the button for the master view in a navigationItem. The UISplitViewControllerDelegate is specifically designed to work with a UIBarButtonItem, you'll probably have to implement a custom popover controller to get that to work.
精彩评论