拆分视图控制器委托和工具栏按钮

时间:2014-02-02 10:44:14

标签: ios objective-c uitableview uisplitviewcontroller

我正在使用普通的委托方法以纵向模式显示按钮,以这种方式显示/隐藏UITableView

我在UITableViewController

中使用此功能
 // Split View Controller
 - (void)awakeFromNib
 {
     [super awakeFromNib];
     self.splitViewController.delegate = self;
 }

 - (id <SplitViewBarButtonItemPresenter>)splitViewBarButtonItemPresenter
{
    id detailVC = [self.splitViewController.viewControllers lastObject];
    if (![detailVC conformsToProtocol:@protocol(SplitViewBarButtonItemPresenter)]) {
        detailVC = nil;
    }
    return detailVC;
}

- (BOOL)splitViewController:(UISplitViewController *)svc
   shouldHideViewController:(UIViewController *)vc
              inOrientation:(UIInterfaceOrientation)orientation
{
    return UIInterfaceOrientationIsPortrait(orientation);
}

- (void)splitViewController:(UISplitViewController *)svc
     willHideViewController:(UIViewController *)aViewController
          withBarButtonItem:(UIBarButtonItem *)barButtonItem
       forPopoverController:(UIPopoverController *)pc
{
    barButtonItem.title = @"Table of Data";
    [self splitViewBarButtonItemPresenter].splitViewBarButtonItem = barButtonItem;
}

- (void)splitViewController:(UISplitViewController *)svc
     willShowViewController:(UIViewController *)aViewController
  invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    [self splitViewBarButtonItemPresenter].splitViewBarButtonItem = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

在我的DetailViewControllerS(多个)我正在使用

- (void)handleSplitViewBarButtonItem:(UIBarButtonItem *)splitViewBarButtonItem
{
    NSMutableArray *toolbarItems = [self.toolbar.items mutableCopy];
    if (_splitViewBarButtonItem) [toolbarItems removeObject:_splitViewBarButtonItem];
    if (splitViewBarButtonItem) [toolbarItems insertObject:splitViewBarButtonItem atIndex:0];
    self.toolbar.items = toolbarItems;
    _splitViewBarButtonItem = splitViewBarButtonItem;
}

- (void)setSplitViewBarButtonItem:(UIBarButtonItem *)splitViewBarButtonItem
{
    if (splitViewBarButtonItem != _splitViewBarButtonItem) {
        [self handleSplitViewBarButtonItem:splitViewBarButtonItem];
    }
}

问题是如果通过“替换Segue”更改详细视图按钮以显示/隐藏新UITableView中的DetailViewController消失,除非我将iPad旋转到横向然后再回到纵向! 或者即使我转到另一个ViewController,它不应该出现按钮,然后返回我的主DetailView,除非我旋转设备,否则按钮不会显示。 如何修复它,如果我处于纵向模式,按钮总是会出现?

1 个答案:

答案 0 :(得分:0)

通常你不应该在这种情况下使用替换segue。

这些委托方法加上NavigationViewController足以显示条形按钮项目。