Alex Rivera | Logout

Hide TabBar when pushed into the navigation stack and bring it back when popped out of the navigation stack

Asked 2011-02-13T04:04:58.967
13

I am trying to do the following.

I have a tab bar controller with 2 tabs in it. Both the tabs are navigation controller with a table view on each of them.

Now when I select one cell of the table in the first tab, I am pushing another tab bar controller, so I would like to hide the tab bar of the parent tabbarcontroller, and when I click the back button on the navigation bar I would like to see the the parent tab bar again, as I am in my parent tab bar view.

I tried hidesbottombarwhenpushed and it hides the parent tab bar controller tab bar but when I click back it doesn't brings it back.

Edit
Report

2 Answers

38

Ok, So finally I got my answer, this is what I am suppose to do.

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

So basically hidesBottomBarWhenPushed = YES, and then push your view controller and then hidesBottomBarWhenPushed = NO; this works like a charm.

Thanks to eddy and his post here

answered 2011-02-14T04:27:05.387
1

As the Apple documentation states, you can't push a UITabBarController instance on a NavigationController. And there's a good reason for that: how do you get back from the pushed tab bar controller if you selected another item in the tab bar?

The simple answer is: don't do that, it will confuse your user. You can try swapping the first view controller for another view controller that may be a tab bar controller, but do not use the push paradigm for that: use an explicit button instead that will swap your first tab bar controller for the second one, preferably using a visual transition.

You can look at the setAnimationTransition:forView:cache: documentation for the UIView class to know how to swap, say, a tab bar controller for another:

  1. Begin an animation block.
  2. Set the transition on the container view.
  3. Remove the subview from the container view.
  4. Add the new subview to the container view.
  5. Commit the animation block.

In this case, the container view will be the application's window.

answered 2011-02-13T22:49:10.423

Your Answer