在纵向模式下按下新视图控制器后,iOS UISplitViewController的Popover控制器按钮消失

问题描述:

在我的UISplitViewController应用程序中,我有

In my UISplitViewController application, I have


  • RootViewController - 左窗格中的视图控制器。

  • DetailViewController - 在右侧窗格中查看控制器。

当一个项目(在点击RootViewController中的UITableView,将设置新的视图控制器,如下所示:

When one item (which is in a UITableView) in RootViewController is tapped, new view controller will be set as the following shows:



[detailViewController setViewControllers:[NSArray arrayWithObjects:newViewController,nil] animated:animated];

/ / detailPane是我的DetailViewController


所有在横向模式下工作得很好。但是,我无法使UISplitViewController在我的肖像模式下工作,也就是说,当我在portait模式下启动并使用应用程序时,RootViewController的弹出按钮在我的DetailViewController中没有正确显示。

All works pretty well in landscape mode. However, I can't make the UISplitViewController work as what I want in portrait mode, that is, the RootViewController's popover button does not appear appropriately in my DetailViewController when I launch and use the application in portait mode.

当我以纵向模式启动应用程序时,弹出按钮会正确显示。但是在弹出窗口中的一个项目并且在detailViewController上设置了新的视图控制器后,该按钮消失了。我必须将设备旋转到横向,然后再次回到纵向再次使按钮出现。

When I launch the app in portrait mode, the popover button appears appropriately. But after tapping one item in the popover and a new view controller has been set on detailViewController, the button disappeared. I have to rotate the device to landscape and then back to portrait again to make the button appear again.

我在我的应用程序的AppDelegate中设置了我的UISplitViewController的委托,如下所示:

I set my UISplitViewController's delegate in my application's AppDelegate as follows:



self.splitViewController.delegate = self.detailViewController


这是我的UISplitViewControllerDelegate实现

And here is my UISplitViewControllerDelegate implementation

- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem  forPopoverController: (UIPopoverController*)pc {
    NSLog(@"Will hide view controller");
    barButtonItem.title = @"Menu";
    [self.navigationItem setLeftBarButtonItem:barButtonItem];
    self.popoverController = pc;
}

- (void)splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
    NSLog(@"Will show view controller")
    NSMutableArray *items = [self.navigationItem.leftBarButtonItems mutableCopy];
    [items removeAllObjects];
    [self.navigationItem setLeftBarButtonItems:items animated:YES];
    [items release];
    self.popoverController = nil;   
}

非常感谢任何提示或帮助。
谢谢。

Any hint or help is greatly appreciated. Thanks.

刚刚想出了一个新的解决方案。

Just came up with a new solution.

Subclass UINavigationController 并实现 UISplitViewControllerDelegate 。将此类的实例设置为splitViewController的右侧ViewController。每次要从主服务器更改详细视图控制器时

Subclass UINavigationController and implement UISplitViewControllerDelegate. Set an instance of this class as the right ViewController of the splitViewController. Everytime you want to change the detail view controller from the master

NewDetailViewController *newDetailVC = ....// Obtain the new detail VC

newDetailVC.navigationItem.leftBarButtonItem = [[[[self.splitViewController.viewControllers objectAtIndex:1]topViewController]navigationItem ]leftBarButtonItem];  //With this you tet a pointer to the button from the first detail VC but from the new detail VC

[[self.navigationController.splitViewController.viewControllers objectAtIndex:1]setViewControllers:[NSArray arrayWithObject:newDetailVC]];  //Now you set the new detail VC as the only VC in the array of VCs of the subclassed navigation controller which is the right VC of the split view Controller

这对我有用,我可以避免定义一个孔协议并将主设置为委托,这是一个很大的权衡。希望它有所帮助。

This works for me and I can avoid defining a hole protocol and setting the master as the delegate, which is a big trade off. Hope it helps.