In my iPad App I'm using a UISplitViewController with two UINavigationControllers as master and detail. In Potrait I'd like the master to be hidden and accessible via UIPopoverViewController. This is the implementation of my UISplitViewController subclass, which works fine:
- (id)init {
self = [super init];
if (self) {
_splitViewController = [[UISplitViewController alloc] init];
_splitViewController.delegate = self;
_searchViewController = [[UIViewController alloc] init];
_searchViewController.view.backgroundColor = [UIColor whiteColor];
_masterNavController = [[UINavigationController alloc] initWithRootViewController:_searchViewController];
_masterNavController.navigationBar.translucent = NO;
_mapViewController = [[MapViewController_iPad alloc] init];
_detailNavController = [[UINavigationController alloc] initWithRootViewController:_mapViewController];
_detailNavController.navigationBar.translucent = NO;
_splitViewController.viewControllers = @[_masterNavController, _detailNavController];
_splitViewController.view.backgroundColor = [UIColor redColor];
}
return self;
}
#pragma mark -
#pragma mark - UISplitViewControllerDelegate
- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc {
svc.view.backgroundColor = [UIColor redColor];
barButtonItem.title = NSLocalizedString(@"ipad_search_vc_bar_button_title", @"Name of the master view controller button on iPad");
[self.mapViewController.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
}
- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
svc.view.backgroundColor = [UIColor redColor];
[self.mapViewController.navigationItem setLeftBarButtonItem:nil animated:YES];
}
- (void)splitViewController:(UISplitViewController *)svc popoverController:(UIPopoverController *)pc willPresentViewController:(UIViewController *)aViewController {
svc.view.backgroundColor = [UIColor redColor];
[pc setPopoverBackgroundViewClass:[CustomPopoverBackgroundView class]];
}
This is how it looks:
After starting the App the first time and tapping the UIBarButton, the master looks like the following:
After hiding and tapping the UIBarButton item the second time, the master looks like it's supposed to. It has the red divider line instead of the standard colored one:
Now, the CustomBackgroundView that is used in the UISplitViewController delegate is actually being instantiated, but somehow not used the first time around.
Any idea how I could force the UIPopOverController to use the CustomBackgroundView the first time?