弹出式按钮未在拆分视图应用中显示

时间:2014-08-12 00:37:15

标签: uisplitviewcontroller uibarbuttonitem popover

我有一个拆分视图应用程序,当设备处于纵向方向且隐藏主视图时,该应用程序应显示菜单按钮。

当应用程序以纵向模式启动时,将执行此功能:

- (void)splitViewController:(UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController:(UIPopoverController*)pc {

    barButtonItem.title = @"Menu";
    self.popoverController = pc;
    self.rootPopoverButtonItem = barButtonItem;
    // Get current detail view (splitVC-->detailNavVC-->currentVC).
    UINavigationController *detailNav = [self.splitController.viewControllers objectAtIndex: 1];
    UIViewController <SubstitutableDetailViewController> *detailViewController = [detailNav.viewControllers objectAtIndex: 0];
    [detailViewController showRootPopoverButtonItem: rootPopoverButtonItem];
}

此函数依次在TitleViewController.m中启动函数:

- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem {
    // Add the popover button to the toolbar.
    NSMutableArray *itemsArray = [toolbar.items mutableCopy];
    [itemsArray insertObject: barButtonItem atIndex: 0];
    [toolbar setItems:itemsArray animated:NO];
}

所有这些代码似乎都正常运行,但没有显示菜单按钮。有任何想法吗?感谢。

1 个答案:

答案 0 :(得分:0)

我似乎通过在设置工具栏项后添加以下行来解决问题:

[self.view reloadInputViews];