我有一个tabBar
+ NavigationViewController
。选项卡栏具有带单元格的集合视图(Say view1),单元格中的push seague实现到另一个视图(Say view2)。
在view2中我想要一个navBar
但没有标签栏。
我试过了
self.tabBarController?.tabBar.hidden = true
,
它适用于view2但是当我通过后退按钮返回view1时,标签仍然被隐藏(即使在view1类中我在viewDidLoad func中添加了self.tabBarController?.tabBar.hidden = false
)。
如何让标签栏重新出现在view1中?
我在迅速工作。
在viewDidload
中将UIViewController hidesBottomBarWhenPushed
设置为yes:
self.hidesBottomBarWhenPushed = YES;
这样,UINavigationController
负责隐藏标签栏。
在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;
}}
=)
Bruno Fernandes在Swift中的回答:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "YourSegueIdentifier" {
let destinationController = segue.destinationViewController as! YourViewController
destinationController.hidesBottomBarWhenPushed = true
}
}
这个答案对我有用。把hidesBottomBarWhenPushed
放在viewDidLoad
方法中是行不通的。
谢谢布鲁诺!
你必须与viewWillAppear
或viewDidAppear
合作。当view1第一次加载(显示)时,将调用viewDidLoad
。如果从view1移动到view2并返回viewDidLoad将不再被调用。因此你必须使用viewWillAppear或viewDidAppear之类的
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.tabBarController?.tabBar.hidden = false
}
将此代码放在view1控制器中。每次导航回view1时都会调用viewWillAppear
或viewDidAppear
如果你想隐藏TabBarController底栏:#Swift 3
在YourViewController中:在ViewDidLoad()方法中
self.tabBarController?.tabBar.isHidden = false