Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show UITabBar when UIViewController pushed

Here's my situation :
I have a UINavigationController inside a UITabBarController. When I drill down the navigation controller, at some point I have to hide the UITabBar because I want the view to have as much space as possible.
I do that by using self.hidesBottomBarWhenPushed = YES inside the pushed UIViewController, and it works quite well.
However, I want to show the UITabBar back in the following pushed controllers. I've tried to put self.hidesBottomBarWhenPushed = NO in the other controllers, but the UITabBar won't come back.

It seems to be normal as the documentation states :

hidesBottomBarWhenPushed

If YES, the bar at the bottom of the screen is hidden; otherwise, NO. If YES, the bottom bar remains hidden until the view controller is popped from the stack.

And indeed, when the controller with this property set to yes is popped, the tabbar does come back.

Is there any proper way to show the UITabBar when a controller is pushed, once it's been hidden?

Thanks in advance

like image 354
kombucha Avatar asked Feb 21 '11 23:02

kombucha


1 Answers

Here's my approach to this when using Storyboards in iOS 5:

Set the hidesBottomBarWhenPushed property to NO before performing the push segue:

- (void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender
{
   if( [segue.identifier isEqualToString:@"PushDetailView"] )
   {
      self.hidesBottomBarWhenPushed = NO;
   }

   [super prepareForSegue:segue sender:sender];
}

The segue identifier is obviously up to you to name.

Set it back to YES immediately when the view controller's view will disappear:

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

   [super viewWillDisappear:animated];
}

Works like a charm (tested on iOS 5.1) using all the right animations for the UITabBar.

like image 103
Michael Thiel Avatar answered Sep 27 '22 20:09

Michael Thiel