【问题标题】:hide tab bar in view with push使用推送在视图中隐藏标签栏
【发布时间】:2015-01-03 00:47:55
【问题描述】:

我有一个tabBar + NavigationViewController。 Tab bar 具有带有单元格的集合视图(例如 view1),并且带有单元格的 push seague 被实现到另一个视图(例如 view2 )。

view2 我想要一个 navBar 但没有标签栏。

我试过了

self.tabBarController?.tabBar.hidden = true,

view2 工作正常,但是当我通过 返回按钮view1 时/strong> 标签仍然隐藏(即使在 view1 类中我在 viewDidLoad 函数中添加了self.tabBarController?.tabBar.hidden = false)。

如何让标签栏重新出现在 view1 中?

我正在快速工作。

【问题讨论】:

    标签: swift uinavigationcontroller uitabbarcontroller pushviewcontroller


    【解决方案1】:

    确保仅在其选项卡的 ViewController 上选中此选项 您希望隐藏的栏。

    感谢iHarshil 的建议。

    【讨论】:

    • 太棒了!很好很容易。确保仅在您希望隐藏其标签栏的 ViewController 上选中此选项。谢谢:)
    【解决方案2】:

    viewDidload 中将UIViewController hidesBottomBarWhenPushed 设置为yes:

    self.hidesBottomBarWhenPushed = YES;
    

    这样UINavigationController 负责隐藏标签栏。

    【讨论】:

    • 我已经在“View2”类有趣的viewDidLoad的代码中添加了这个,但它不起作用......还有其他方法吗
    • 对不起..代码是在 View2 中编写的,所以它不起作用......现在我将代码转移到 view1 类并且选项卡隐藏在 View2 中但是当我再次返回 view1 时它没有'不显示..
    • 谢谢!这对我很有用。
    • 这会永远隐藏 TabBar,即使在弹回导航控制器堆栈的根目录后也是如此。
    • 不要将它添加到 ViewController1。否则您将永远隐藏它。当您实例化 ViewController2 时,您在推送它之前执行它。 ``` let vc2 = ViewController2() vc2.hidesBottomBarWhenPushed = true navigationController?.pushViewController(vc2, animated: true) ``` 那么当你弹回V1时它会重新出现。
    【解决方案3】:

    prepareForSegue中使用:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        if ([segue.identifier isEqualToString:@"showRecipeDetail"]) {
            NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
            RecipeDetailViewController *destViewController = segue.destinationViewController;
            destViewController.recipeName = [recipes objectAtIndex:indexPath.row];
    
            // Hide bottom tab bar in the detail view
            destViewController.hidesBottomBarWhenPushed = YES;
        }
    }
    

    【讨论】:

      【解决方案4】:

      布鲁诺·费尔南德斯在 Swift 中的回答:

      override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
          if segue.identifier == "YourSegueIdentifier" {
              let destinationController = segue.destinationViewController as! YourViewController
              destinationController.hidesBottomBarWhenPushed = true
          }
      }
      

      这是对我有用的答案。将hidesBottomBarWhenPushed 放在viewDidLoad 方法中不起作用。

      谢谢布鲁诺!

      【讨论】:

      • 错字,控制器应该是:destinationController.hidesBottomBarWhenPushed = true
      • 我完全同意 Felipe,这将适用于更多场景。仅在 viewDidLoad() 中设置此属性并不总是有效。谢谢!
      【解决方案5】:

      就我而言,我在推送目标视图控制器之前使用hidesBottomBarWhenPushed

      func showSecondViewController() {
        let vc = SecondViewController()
        vc.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(vc, animated: true)
      }
      

      【讨论】:

      • 这对我也有用。我正在使用带有 tabBar 的 CollectionView。我不想要详细视图控制器上的标签栏,所以我把这一行放在我的 didSelectItemAt
      • 节省大量时间。谢谢
      【解决方案6】:

      您必须使用viewWillAppearviewDidAppearviewDidLoad 将在 view1 第一次加载(显示)时被调用。如果您从 view1 移动到 view2 并返回 viewDidLoad 将不会再次被调用。因此,您必须使用 viewWillAppear 或 viewDidAppear 之类的

      override func viewWillAppear(_ animated: Bool) {
          super.viewWillAppear(animated)
      
          self.tabBarController?.tabBar.hidden = false
      }
      

      将此代码放入您的 view1 控制器中。每次导航回 view1 时都会调用 viewWillAppearviewDidAppear

      【讨论】:

      • 在 Swift 4 中是 self.tabBarController?.tabBar.isHidden = false
      【解决方案7】:

      如果你想隐藏 TabBarController 底栏:#Swift 3

      在 YourViewController 中:在 ViewDidLoad() 方法中

      self.tabBarController?.tabBar.isHidden = false
      

      【讨论】:

        猜你喜欢
        • 2011-11-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-29
        • 2012-11-30
        • 2016-05-27
        • 1970-01-01
        相关资源
        最近更新 更多