views:

906

answers:

2

I've come across this twice now.

Sometimes using the following line of code:

[self.navigationController presentModalViewController:aViewController animated:YES];

displays the view, but the navigation bar is then hidden.

I can write:

[self.navigationController setNavigationBarHidden:NO];

to my hearts content, everywhere I can think of with no effect.

Has anyone ran into this?

Am I doing something silly?

+6  A: 

No, I ran into this as well. The problem is that when you present a modal view controller with a UIViewController based class, it does not extend the calling navigation controller's nav bar onto the modal. The modal view covers the entire screen. What I ended up doing to solve the problem was to create a UINavigationController and push the UIViewController based class onto it, and then do presentModalViewController to the navigation controller's instance.

like:

UIViewController *vc = [[UIViewController alloc] init];
UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentModalViewController:cntrol animated:YES];
[cntrol release];

That allowed me to have a nav bar at the top.

I am not sure if that will help in your particular case, the only other thing I would suggest is to replicate the behavior of the modal with a UIAnimation that stops 44px below the top of the phone. That would keep the original navigation bar visible.

Heat Miser
Oh man, I'm stupid. I didn't need THE navigation controller at the top, just a tool bar, any tool bar. Thanks
Corey Floyd
By the way, thanks for putting that song in my head for the past 5 hours. I feel like it's christmas.
Corey Floyd
I've had it running through my head for a long time :-)
Heat Miser
Thanks. Your answer works.
Warrior
Had the same issue myself. The solution works well, thanks!. Voted Up :)
alexb
A: 

Maybe this is obvious, but once you're done with the modal view and want to dismiss it, you should do something like this in your modal vc:

[parentController dismissModalViewControllerAnimated:YES];

Where parentController is a reference to the vc from where you are presenting the modal view.

Fede Mika