使用推送隐藏标签栏

问题描述 投票:16回答:6

我有一个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中?

我在迅速工作。

swift uinavigationcontroller uitabbarcontroller pushviewcontroller
6个回答
30
投票

viewDidload中将UIViewController hidesBottomBarWhenPushed设置为yes:

self.hidesBottomBarWhenPushed = YES;

这样,UINavigationController负责隐藏标签栏。


27
投票

enter image description here

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

感谢iHarshil的建议。


24
投票

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

=)


18
投票

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方法中是行不通的。

谢谢布鲁诺!


3
投票

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

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    self.tabBarController?.tabBar.hidden = false
}

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


1
投票

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

在YourViewController中:在ViewDidLoad()方法中

self.tabBarController?.tabBar.isHidden = false
© www.soinside.com 2019 - 2024. All rights reserved.