开发者

How to use hidesBottomBarWhenPushed if i want to hide the tabbar for only one kind of controller?

I have gotten in trouble while using hidesBottomBarWhenPushed... I will push three controllers – A, B, and C – into navigationcontroller in order, and I would like to hide bottom tab bar when B is shown.(and A is one of the tabbar controllers)

Does any one h开发者_StackOverflow中文版ave ideas?


In view controller A (which is on the tabBar), when it comes time to present B (no tabBar wanted):

self.hidesBottomBarWhenPushed = YES; // hide the tabBar when pushing B
[self.navigationController pushViewController:viewController_B animated:YES];
self.hidesBottomBarWhenPushed = NO; // for when coming Back to A

In view controller B, when it comes time to present C (tabBar wanted again):

self.hidesBottomBarWhenPushed = NO; // show the tabbar when pushing C
[self.navigationController pushViewController:viewController_C animated:YES];
self.hidesBottomBarWhenPushed = YES; // for when coming Back to B


Instead of setting it in viewDidLoad, I have found that sometimes this is too late. Set it in init or override hidesBottomBarWhenPushed to return YES for views with no bottom toolbar.


From hidesBottomBarWhenPushed documentation:

If YES, the bottom bar remains hidden until the view controller is popped from the stack.

This means that if you don't necessarily know the order the View Controllers will be pushed, you'll need all the view controllers from the stack to have its hidesBottomBarWhenPushed set to false except for the topViewController.

So what I do

  1. before pushing the new View Controller I set its hidesBottomBarWhenPushed property as desired
  2. also before pushing the I set self.hidesBottomBarWhenPushed to ensure the whole stack until the next one will have its property set to false
  3. before popping, that's when I check if the tabBar should be displayed or not, and update its hidesBottomBarWhenPushed

Here's some code for 1 and 2)

  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    self.hidesBottomBarWhenPushed = false

    if (segue.identifier == "MyViewControllerWhoHidesTabBar") {
      let viewController: MyViewControllerWhoShowsTabBar = segue.destinationViewController as! MyViewControllerWhoShowsTabBar
      viewController.hidesBottomBarWhenPushed = true
    }
       // rest of implementation....
 }

3) I've overriden the back button action to

  func backButtonClick(sender:UIButton!) {
    let viewControllers = self.navigationController!.viewControllers
    if let vc = viewControllers[viewControllers.count-2] as? MyViewController {
      if vc.isKindOfPageYouDontWannaShowTheTabBar() == true {
        vc.hidesBottomBarWhenPushed = true
      }
    }
    navigationController?.popViewControllerAnimated(true)
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜