在我的 iPad 应用程序中,我使用带有两个UINavigationControllers作为主控和细节的UISplitViewController 。在 Potrait 中,我希望通过UIPopoverViewController隐藏和访问主控。这是我的UISplitViewController子类的实现,它工作正常:
- (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]];
}
这是它的外观:
第一次启动 App 并点击UIBarButton后,master 如下所示:
在第二次隐藏并点击UIBarButton项目后,主人看起来应该这样做。它有红色分隔线,而不是标准的彩色分隔线:
现在,在UISplitViewController委托中使用的CustomBackgroundView实际上正在被实例化,但不知何故第一次没有使用。
知道如何强制UIPopOverController第一次使用CustomBackgroundView吗?