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

时间:2010-06-01 06:29:39

标签: iphone uinavigationcontroller uitabbarcontroller

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

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

- (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;
}

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

提前致谢

8 个答案:

答案 0 :(得分:81)

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

articleController.hidesBottomBarWhenPushed = YES;

答案 1 :(得分:25)

如果你更喜欢故事板配置而不是编码,那么就有一个切换。只需转到destinationViewController>属性检查器:

enter image description here

答案 2 :(得分:11)

一个非常简单的解决方案:

 destinationViewController.hidesBottomBarWhenPushed = YES;

在你的情况下:

 articleController.hidesBottomBarWhenPushed = YES;

希望这有帮助!

答案 3 :(得分:3)

您可以通过故事板简单隐藏父标签栏。

选择 viewcontroller > 属性检查器> 检查 在推送时隐藏底栏

答案 4 :(得分:1)

您可以在视频控制器中添加以下代码。

-(BOOL)hidesBottomBarWhenPushed
{ 
     return YES;
}

这将仅隐藏推送视图控制器中的标签栏,当您弹出视图控制器时,标签控制器仍然取消隐藏所有视图控制器。

Swift版本(3.x及以上版本)

override var hidesBottomBarWhenPushed: Bool {
    get {
        return navigationController?.topViewController == self
    }
    set {
        super.hidesBottomBarWhenPushed = newValue
    }
}

由于

答案 5 :(得分:0)

对于swift 3,你可以在下面的pushviewController代码之前取消隐藏tabbar的相同代码

   var frame = self.tabBarController?.tabBar.frame
    frame?.origin.y = self.view.frame.size.height - (frame?.size.height)!+112
    UIView.animate(withDuration: 0.2, animations: {
        self.tabBarController?.tabBar.frame = frame!
    })
    self.navigationController?.pushViewController(viewController, animated: true)

或使用whant取消隐藏tabbar你可以使用

  viewController.hidesBottomBarWhenPushed = false

答案 6 :(得分:0)

enter image description here

转到Xcode中的界面构建器 - >打开属性检查器并检查项目'在推送'上隐藏底栏对于视图控制器,您不想显示标签栏。它会工作!!

答案 7 :(得分:0)

在要隐藏的控制器中使用属性hidesBottomBarWhenPushed

对于隐藏,所有控制器都放入prepare for segue

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    segue.destination.hidesBottomBarWhenPushed = true
}