【问题标题】:How to hide parent tabbar when pushing controller in navigationController在导航控制器中推送控制器时如何隐藏父标签栏
【发布时间】:2011-02-26 05:19:36
【问题描述】:

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

一切正常,但在将详细信息视图推送到导航控制器时我注意到了一个问题。在属于标签栏控制器的 tableviewcontroller 的 didSelectRowAtIndexPath 中(图像中称为最新的那个)我正在这样做:

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

提前致谢

【问题讨论】:

    标签: ios swift iphone uinavigationcontroller uitabbarcontroller


    【解决方案1】:

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

    articleController.hidesBottomBarWhenPushed = YES;
    

    【讨论】:

    • 重要说明是在创建targetViewController后立即设置hidesBottomBarWhenPushed
    【解决方案2】:

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

     destinationViewController.hidesBottomBarWhenPushed = YES;
    

    在你的情况下:

     articleController.hidesBottomBarWhenPushed = YES;
    

    希望这会有所帮助!

    【讨论】:

      【解决方案3】:

      如果您更喜欢故事板配置而不是编码,则可以使用一个切换开关。只需转到destinationViewController > Attribute Inspector:

      【讨论】:

      • 我不知道为什么这被否决了,但这确实对我有用。
      【解决方案4】:

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

      -(BOOL)hidesBottomBarWhenPushed
      { 
           return YES;
      }
      

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

      Swift 版本(3.x 及以上)

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

      谢谢

      【讨论】:

      • 谢谢,节省我的时间:)
      【解决方案5】:

      对于 swift 3,通过在 pushviewController 代码之前取消隐藏标签栏来编写相同的代码,如下所示

      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 来取消隐藏你可以使用的标签栏

      viewController.hidesBottomBarWhenPushed = false
      

      【讨论】:

        【解决方案6】:

        enter image description here

        转到 Xcode 中的界面构建器 -> 打开属性检查器并检查项目 'Hide Bottom bar on Push' 以获取您不想显示标签栏的视图控制器。它会工作的!

        【讨论】:

          【解决方案7】:

          您可以通过情节提要简单地隐藏父标签栏。

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

          【讨论】:

            【解决方案8】:

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

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

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

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2010-12-09
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2012-06-23
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多