如何在navigationController中按下控制器时隐藏父标签栏

Yan*_*nis 25 iphone uitabbarcontroller uinavigationcontroller ios swift

我有一个带标签栏控制器的应用程序,每个视图都包含一个导航控制器.我的MainWindow如下所示:alt text http://www.freeimagehosting.net/image.php?7bc867a594.png

一切正常,但我注意到将详细信息视图推送到导航控制器时出现问题.在forSelectRowAtIndexPath中,对于属于选项卡栏控制器(图像中名为Latest)的tableviewcontroller,我这样做:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ArticleViewController *articleController = [[ArticleViewController alloc] initWithNibName:@"ArticleView" bundle:nil];

    [self.navigationController pushViewController:articleController animated:YES];

    [articleController release];
    articleController = nil;
}
Run Code Online (Sandbox Code Playgroud)

}

ArticleViewController有自己的tabbar,因为它需要显示不同的东西.问题是,当我将ArticleViewController推入navigationController时,我会在视图底部看到两个标签栏.有什么办法可以解决这个问题吗?

提前致谢

Yan*_*nis 88

在花了几个小时并在这里发布一个问题后,我发现这个问题的解决方案是在ArticleController实例化之后添加以下行.

articleController.hidesBottomBarWhenPushed = YES;
Run Code Online (Sandbox Code Playgroud)

  • 重要说明是在创建targetViewController之后立即设置了“ hidesBottomBarWhenPushed” (4认同)

Vik*_*era 27

如果你更喜欢故事板配置而不是编码,那么就有一个切换.只需转到destinationViewController> Attribute Inspector:

在此输入图像描述


小智 12

非常简单的解决方案:

 destinationViewController.hidesBottomBarWhenPushed = YES;
Run Code Online (Sandbox Code Playgroud)

在你的情况下:

 articleController.hidesBottomBarWhenPushed = YES;
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!


Tee*_*aul 5

您可以在您正在推送的视图控制器中添加以下代码。

-(BOOL)hidesBottomBarWhenPushed
{ 
     return YES;
}
Run Code Online (Sandbox Code Playgroud)

这将仅隐藏推送视图控制器中的选项卡栏,并且当您弹出视图控制器选项卡栏时,在其余所有视图控制器中保持取消隐藏状态。

Swift 版本(3.x 及以上)

override var hidesBottomBarWhenPushed: Bool {
    get {
        return navigationController?.topViewController == self
    }
    set {
        super.hidesBottomBarWhenPushed = newValue
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢


Dee*_*eep 5

您可以通过 storyboard 简单地隐藏父标签栏。

选择viewcontroller > Attribute Inspector >选中 Hide Bottom Bar on Push