I have a navigation controller. For one of the views i want to hide the bottom tab bar, so it gets the max possible screen real estate. To do this, i have:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.hidesBottomBarWhenPushed = YES; // To hide the tab bar
    }
    return self;
}
But for the next view that i push on the stack, i want the tab bar to reappear. Is there a way to do this?
I'm have solved this problem like that:
Almost all my ViewControllers are children of BaseViewController.
So, example:
class BaseVC: UIViewController {
    final override var hidesBottomBarWhenPushed: Bool {
        get {
            if navigationController?.viewControllers.last == self {
                return prefersBottomBarHidden ?? super.hidesBottomBarWhenPushed
            } else {
                return false
            }
        } set {
            super.hidesBottomBarWhenPushed = newValue
        }
   }
   private(set) var prefersBottomBarHidden: Bool?
}
Just override variable "prefersBottomBarHidden" in ViewController where BottomBar should be hidden:
override var prefersBottomBarHidden: Bool? { return true }
As of iOS5, there's a very easy means of accomplishing this. It's essentially the same method as Deepak, but there aren't any artifacts with the animation - everything looks as expected.
On init, set
self.hidesBottomBarWhenPushed = YES;
just as you have above. When it's time to push the new controller on the stack, it's as simple as:
self.hidesBottomBarWhenPushed = NO;
UIViewController *controller = [[[BBListingController alloc] init] autorelease];
[self.navigationController pushViewController:controller];
self.hidesBottomBarWhenPushed = YES;
It's important to reset the value to YES after the controller has been pushed in order to re-hide the bar when the user taps the Back button and the view comes back into view.
It's been a while since this question was asked, but none of these answers address using Storyboard segues. It turns out to be pretty easy:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "MyViewControllerIdentifier" {
        // Hide the tabbar during this segue
        hidesBottomBarWhenPushed = true
        // Restore the tabbar when it's popped in the future
        DispatchQueue.main.async { self.hidesBottomBarWhenPushed = false }
    }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With