hidesBottomBarWhenPushed = NO not working?

25,730

Solution 1

This is what the documentation for hidesBottomBarWhenPushed says (emphasis added):

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

So it looks like the behavior you're seeing is just what the documentation says will happen. You start by pushing a view controller onto the stack which has hidesBottomBarWhenPushed = YES. At that point, pushing other view controllers onto the stack won't change the hiddenness of the bottom bar. As long as that first view controller is on the stack, the bottom bar will remain hidden.

So I think you'll have to come up with a different way of accomplishing your UI goal. One option would be to present the first view controller as a modal view controller over the tab bar controller's view. Then, when you want to go to the second view controller just dismiss the first one and voila. The only visual difference will be the transition animation.

There are surely other options too, but that just came first to my mind.

Good luck!

Solution 2

This is an issue that has bugged me for a while, and I only just found a solution that works. The hidesBottomBarWhenPushed property is a very strange beast, and works in, to my mind, a counter-intuitive way.

The problem with it is that when you push a new view controller (or pop back) the navigationController will ask all view controllers (from top to bottom) if they want to hide the bottom bar, and if any of them say YES the tabbar will be hidden, which is why the tabbar remains hidden despite setting NO to hiding on the new view controller.

Here is my solution - override the hidesBottomBarWhenPushed getter in the view controller that you wish to not have a tabbar, and check if it is at the top of the stack:

Objective-C

- (BOOL) hidesBottomBarWhenPushed
{
    return (self.navigationController.topViewController == self);
}

Swift (not so obvious, hence snippet)

override var hidesBottomBarWhenPushed: Bool {
    get {
        return navigationController?.topViewController == self
    }
    set {
        super.hidesBottomBarWhenPushed = newValue
    }
}

This nicely encapsulates the hide/show logic in one place, so you dont have to think about it outside of the viewcontroller that does the hiding.

Solution 3

I had the same issue, but after 3 hours I was found solution! In this topic answered Oct 8 '10, Dave Batton said:

Right way to use hidesBottomBarWhenPushed property is:

self.anotherViewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:self.anotherViewController animated:animated];

Solution 4

Not sure if a solution was found for this but I just managed to get this working.

My scenario:

I have a UITabBarController with 4 tab bar items. On one of the tab bar items it loads a UIViewController with buttons on it. The buttons calls a IBOutlet function that loads another UIViewController which contains the a tab bar at the bottom.

After many trial & error........

On the IBOutlet function, I do the following:

{
 self.hidesBottomBarWhenPushed = YES;
 /* Push the new controller with tab bar */
}

This was working fine with the UITabBarController's tab bar sliding to the left and my tab bar from the pushed controller sliding from the right.

Obviously from functionality perspective I need to push the initial UITabBarController's tar bar back in when "going back".

After many trial & error........

I have the method viewWillDisappear in the UIViewController that pushes the UIViewController with tab bar as:

- (void) viewWillDisappear:(BOOL)animated
{
    self.hidesBottomBarWhenPushed = NO;
}

I ran a few quick tests on this in the simulator and it seems to work fine.

Some contributors suggests that this is bad UI but I am trying this out at the moment to see how it works out.

Happy to receive (cop) any feedbacks. :)

Solution 5

I think you misunderstood the hidesBottomBarWhenPushed use. If YES, the bottom bar remains hidden until the view controller is popped from the stack.

So if I understand your question correctly:

The secondViewController should be the YES, the firstViewController should be the NO.

Share:
25,730

Related videos on Youtube

rottendevice
Author by

rottendevice

Updated on July 09, 2022

Comments

  • rottendevice
    rottendevice almost 2 years

    I have a UITabBar in my app, which I'm hiding on the first UIViewController in the first tab by putting this line in the AppDelegate:

    // ... in MyAppDelegate.m
    firstViewController.hidesBottomBarWhenPushed = YES;
    

    In the firstViewController, the user can push a UIButton that pushes a new UIViewController in the same tab. I'd like for the UITabBar to be visible again when this happens. I'm trying to make it come back like this:

    //... in firstViewController.m
    
    secondViewController = [[SecondViewController alloc] init];
    secondViewController.hidesBottomBarWhenPushed = NO;
    [[self navigationController] pushViewController:secondViewController animated:YES];
    

    Unfortunately, does not bring back the UITabBar. It remains hidden.

    How do I properly bring bar the UITabBar after hiding it?

    Thanks in advance.

  • rottendevice
    rottendevice about 13 years
    I think I got it right actually. I don't want the tab bar to show on the first ViewController of the first tab. I do, however, want it to appear on the second ViewController of the first tab. I know that's weird, but it makes sense in the context of the app.
  • rottendevice
    rottendevice about 13 years
    Ah, that explains it, thanks. I really wish it was "until a new view controller is pushed to or popped from the stack", but what can you do? I'm looking into alternatives now.
  • Nida
    Nida about 13 years
    Yeah, bummer. Give a modal view controller a try. Good luck!
  • deadbeef
    deadbeef over 9 years
    Great answer ! I think it gives the result everyone expects. Each view controller should be allowed to choose whether it wants the bottom bar or not.
  • sachadso
    sachadso over 8 years
    Thanks so much, you just made my day, it was driving me crazy :) This is retarded, it should work this way out of the box, at least that's the behaviour everyone expects I guess.
  • NKorotkov
    NKorotkov over 8 years
    This is awesome and so easy. I think Apple should've added this behaviour as an option.