views:

4534

answers:

3

I have a UITabBarController where the default view controller is a UINavigationController. I want to be able to hide the UITabBar of the UITabBarController when I push a certain view in the UINavigationController.

I've tried adding:

delegate.tabBarController.hidesBottomBarWhenPushed = YES;

in my UINavigationController before I push the view, but that doesn't seem to do the trick.

Any tips on what I should be doing or if it's even possible? Thanks in advance!

+6  A: 

The hidesBottomBarWhenPushed doesn't apply to tab bars. It applies to button bars that you have configured on the UIViewController inside the UINavigationController.

I'm guessing your app has the UINavigationController inside the UITabBarController (this is the standard arrangement). This means that pushing a new navigation view can't affect the UITabBar (since the tab bar is outside the control of the UINavigationController).

There are two ways around this:

  1. Put the tab bar inside the navigation control (push the UITabBarController into the navigation controller). The tab bar will slide left/right as any normal UIViewController.

  2. Use a modal view controller instead (this will replace the whole screen but animates differently to standard navigation views). The advantage with this is it presents a clear, distinct interface -- good for special behavior. Read documentation for presentModalViewController:animated: (or interweb search it) for details on how this is done.

edit: If you want tabs/bars within a view, perhaps you should consider using UISegmentedControl (for tab-like control) or UIToolbar (for bars).

Matt Gallagher
If I set an outlet for the `UITabBarController` in the delegate, can't I control the `UITabBarController`?
Benny Wong
Yes, you can control a tab bar through an outlet but it doesn't really have any methods to temporarily hide the bar, only to switch/configure the tabs. This is in accordance with Apple's intent for the tab bar: that if used, it be a fixed UI item for the duration of the app.
Matt Gallagher
Ah, thanks Matt for the help!
Benny Wong
I just tested this and it seems that setting hidesBottomBarWhenPushed on the view controller to be pushed *will* hide a top-level UITabBar. The trouble with presentModalViewController:animated: is that it pulls up a full-screen view from the bottom, where hidesBottomBarWhenPushed will make the UITabBar slide out to the left.I think Tweetie 2 shows that this can work well and in accordance with the Human Interface Guidelines.
Ryan McCuaig
+2  A: 

It turns out that if you set the view hidesBottomBarWhenPushed:YES it hides the bar when the view appears (duh on my part). I was assigning it to the UITabBarController, which doesn't make too much sense when you think about it.

[self.view hidesBottomBarWhenPushed:YES];
[super pushViewController:viewController animated:animated];
Benny Wong
that's wrong. both methods should be applied to the view controller you are going to push in..
Fossli
+10  A: 

This is better:

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

You have to set hidesBottomBarWhenPushed = YES on the controller you are going to push into the view...

Fossli
This is definitely better. Thank you!
givp