2

我只想在父控制器上显示标签栏,而不是在任何子控制器上。

我正在推送:

childViewController?.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(childViewController!, animated: true)

现在,当我通过单击“返回”按钮向后导航时,该栏再次显示在父级上。

但是如果我像这样以编程方式做同样的事情:

childViewController?.hidesBottomBarWhenPushed = true
self.navigationController?.popToRootViewController(animated: true)
//or
self.navigationController?.popViewController(animated: true)

然后标签栏不再显示在父级上。

我已经尝试了许多解决方案,例如;

解决方案1:在孩子中编写此代码

- (void)viewWillAppear:(BOOL)animated { 
    self.hidesBottomBarWhenPushed = true 
}
- (void)viewWillDisappear:(BOOL)animated {
    self.hidesBottomBarWhenPushed = false 
}

解决方案 2:在推送时编写此代码

childViewController?.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(childViewController!, animated: true)
childViewController?.hidesBottomBarWhenPushed = false

都没有奏效。如果我使用导航栏后退按钮导航回来,一切正常。但如果我popViewControllerpopToRootViewController然后它不起作用。

使用:XCode 8.3.2、Swift 3

请帮帮我。先感谢您。

4

1 回答 1

0

在要隐藏的控制器中使用这种方式:

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    self.hidesBottomBarWhenPushed = true
}
于 2020-03-03T07:41:09.813 回答