0

我无法通过在详细视图中按左键来显示主视图(即 UITabBarController)。下面的代码是我如何实现 UISplitViewControllerDelegate 来设置左按钮。

我正在使用 iOS 6 和 Xcode 4.5。

#pragma mark - UISplitViewControllerDelegate
#warning "incomplete implementation"

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

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

    NSMutableArray *toolbarItems = [self.toolbar.items mutableCopy];
    [toolbarItems insertObject:barButtonItem atIndex:0];
    self.toolbar.items = [toolbarItems copy];
}

- (void)splitViewController:(UISplitViewController *)svc
     willShowViewController:(UIViewController *)aViewController
  invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
    NSMutableArray *toolbarItems = [self.toolbar.items mutableCopy];
    [toolbarItems removeObject:barButtonItem];
    self.toolbar.items = [toolbarItems copy];
}
4

2 回答 2

0

问题解决了。我用 UINavigationController 替换了 UIToolbar,现在我可以通过单击左侧按钮来显示主视图。

于 2012-12-15T10:45:49.327 回答
0

为了将来参考,通过设置拆分视图控制器委托并实现这两种方法,您应该可以开始使用了。

- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)button
    {
        //remove button from navigation bar in detail navigation controller
        ((UINavigationController*)[svc.viewControllers objectAtIndex:1]).topViewController.navigationItem.leftBarButtonItem = nil;
    }

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

        //add button to navigation bar in detail navigation controller
        barButtonItem.title = @"Navigation";
        ((UINavigationController*)[svc.viewControllers objectAtIndex:1]).topViewController.navigationItem.leftBarButtonItem = barButtonItem;

    }

barButtonItem 的实例为您处理所有切换过程。

于 2013-03-12T15:45:25.747 回答