views:

480

answers:

3

I have a UINavigationController in which the root view doesn't display the top navigation bar via
[[self navigationController] setNavigationBarHidden:YES animated:NO];

The view I'm pushing onto this does need to display the navigation bar, and I'm currently using the above method to show it and then hide it again when the view is popped. This results in some weird going-ons, which I would like not to have going on.

EDIT: To clarify, right now I'm using [[self navigationController] setNavigationBarHidden:NO animated:NO]; in the pushed view, and what's happening is the navigationBar appears in both the outgoing view and the new one, and it looks pretty messy to have that flash happen. Here's what's currently happening: alt text

And What I'd like: alt text

Instead what I would like is for the navigation bar to already be showing while the view is being pushed, and not on the root view, much like the behaviour of the hidesBottomBarWhenPushed property.

Can anyone point me in the right direction here?

+1  A: 

What if you put:

[[self navigationController] setNavigationBarHidden:NO animated:NO];

in your pushed view controller's -viewDidLoad method?

Alex Reynolds
Not what I'd like :(See above images.
Kelso.b
Actually just setting your answer to animated:YES does the trick. I'll give it to you.
Kelso.b
+1  A: 

I've noticed that the transitions are much smoother (no weird flicker) if you allow them to animate. Switch your animated flag to YES and see if that smooths things out.

[[self navigationController] setNavigationBarHidden:YES animated:YES];
[[self navigationController] setNavigationBarHidden:NO animated:YES];

Also, I uncheck the "Shows Navigation Bar" checkbox in the IB inspector for my navigation controller rather than doing it in code. That way its default state is hidden when thawed from the xib. The code should effectively do the same thing, but it may be worth trying as I don't have the problem you describe when implementing the same thing.

Matt Long
A: 

Two comments. I am doing the same thing and I agree that it does seem to work better when animated. Also you should be calling it in viewWillAppear or viewDidAppear. Personally I am using viewDidAppear and animated:YES and think that look pretty good.

Since you are setting a application level setting you need to make sure you call it at the right time to avoid the issues you are seeing.

Aaron