ios – iPad SplitViewController以编程方式显示Popover

我有一个iPad SplitViewController应用程序,我在其中以纵向和横向模式隐藏左窗格.当应用程序收到某个通知时,我需要在其弹出窗口中显示左窗格.尽管尝试了许多不同的建议解决方案,但我仍在努力研究如何实现这一目标.

我正在使用包含以下代码的MultipleMasterDetailManager实现:

/* forward the message to the current detail view
 * all detail views must implement UISplitViewControllerDelegate
 */
-(void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc
{
    self.masterBarButtonItem = barButtonItem;
    self.masterPopoverController = pc;

    barButtonItem.title = NSLocalizedString(@"Show Sidebar", @"Show Sidebar");

    [self.currentDetailController.navigationItem setLeftBarButtonItem:self.masterBarButtonItem animated:YES];
}

/* forward the message to the current detail view
 * all detail views must implement UISplitViewControllerDelegate
 */
-(void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    //if (![self.currentDetailController isKindOfClass:[SyncSourceDetailViewController class]])
    //{
        self.masterBarButtonItem = nil;
        self.masterPopoverController = nil;

        [self.currentDetailController.navigationItem setLeftBarButtonItem:nil animated:YES];    
    //}    
}

细节视图控制器本身存在类似的方法.

收到通知时我打电话的方法如下:

- (void)navigateToLatest 
{   
        [self navigateToDocumentsTab];  
        [[self dataLoader] navigateToLatest];  // populates data for the left table view 
        UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
        UIView *view = [[[[[splitViewController viewControllers] objectAtIndex:1] viewControllers] objectAtIndex:0] view];  

        [self.masterDetailManager.masterPopoverController presentPopoverFromRect:CGRectMake(0, 0, 100, 100) inView:view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

这不起作用.我也试过使用presentPopoverFromBarButtonItem方法,但我似乎无法在代码中找到leftBarButtonItem.

也许我完全以错误的方式解决这个问题.

最佳答案 我最终通过在navigateToLatest方法中将我的app委托中的“showSidebar”变量设置为true来解决此问题.然后在我的DetailViewController的ViewDidAppear事件中,检查此变量的值,如果为true,则使用以下代码显示侧栏:

UIPopoverController *masterPopoverController= [[theAppDelegate masterDetailManager] masterPopoverController];
        [masterPopoverController presentPopoverFromBarButtonItem:[self.navigationItem leftBarButtonItem] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
        [theAppDelegate setShowSidebar:NO];
点赞