UISplitViewController的详细信息视图中的左键无法显示UITabBarController(即主视图)

时间:2012-12-14 16:35:52

标签: xcode ios6 uitabbarcontroller uisplitviewcontroller

我无法通过按详细视图中的左按钮来显示主视图(即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];
}

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分: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的实例为您处理所有切换过程。