0

对于不耐烦的人:

我想要一个导航控制器,它的根视图控制器是一个标签栏控制器,类似于 iPad 应用程序。我正在使用 IOS 5 和情节提要。

对于阅读倾向:

在我的故事板中,我在嵌入 UINavigationController 的 UITabBarController 中有 6 个选项卡,在显示 3 个选项卡后给它一个“更多”按钮。

当按下更多时,这样做会给我两个导航栏:

双导航栏...这是什么意思?!

所以我继承了 TabBarController:

//@implentation MyTabController

- (void)viewDidLoad
{
    self.moreNavigationController.wantsFullScreenLayout = NO;
    self.delegate = self;
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    // hide nav bar if current controller is "More" controller
    self.navigationController.navigationBarHidden = 
       viewController == self.moreNavigationController;
}

太好了,这给了我:

差不多好了

我的猜测是我需要重新布局视图以说明状态栏,所以我尝试

[self.view setNeedsLayout:YES];

但我收到一条错误消息,说 UIView 不包含 setNeedsLayout 的选择器,所以...如何让 moreNavigationController.navigationBar 来说明状态栏?

更新
我有第二个相关问题。当我点击“编辑”按钮时,编辑控制器会模态显示。它的导航栏显示在受保控制器下方(在动画之后),并且不接收触摸。

4

2 回答 2

1

不建议将 tabBarController 推入 NavController,而是为每个 tabBar 视图控制器设置一个 NavigatorController,并将 TabBarController 设置为主窗口根视图控制器。

如果您希望能够在显示选项卡栏之前显示一个屏幕,一种解决方案是将所有导航器控制器推入前一个视图控制器,然后是您要显示的那个(这样所有导航栏都有后退按钮)。然后设置hidesBottomBarWhenPushed = YES为第一个视图控制器,这样它就不会显示 tabBar

示例代码:

UIViewController *prevc = [[UIViewController alloc] init];
//prevc.hidesBottomBarWhenPushed = YES;

//Do this for every VC that will be a tabBarItem
UIViewController *vc1 = [[UIViewController alloc] init];
UINavigationController *nv1 = [[UINavigationController alloc] initWithRootViewController:prevc];
[nv1 pushViewController:vc1 animated:NO];

//Remember to set the tabBarItem!

UITabBarController *tb = [[UITabBarController alloc] init];
tb.viewControllers = [NSArray arrayWithObjects:nv1, nv2, nv3, nil];

刚刚意识到设置 hidesBottomBarWhenPushed 到之前的 ViewController 是不行的,但是如果你先显示 prevc,然后再推送下面的 viewController,就没有问题了。但是,如果无论如何您不想在弹出时隐藏标签栏,请检查:

于 2012-06-14T19:38:05.977 回答
0

我也遇到过类似的问题。在我的应用程序中,导航控制器内也有一个 Tabarcontroller。当我尝试以编程方式切换到更多导航控制器中的视图控制器时(例如:[self.tabBarController setSelectedIndex:X];),我的应用程序中会出现相同的问题。但是下面的代码解决了我的问题。

    self.tabBarController.moreNavigationController.navigationBarHidden = YES;
于 2014-07-16T13:45:59.997 回答