I have a menu screen that implements UINavigationController
and on top of that screen, using presentModalViewController
, I place another screen on which I want to have another UINavigationController
. I have tried to implement another navigation controller to handle the new screen but I either get a navbar 1/8th the way down the screen and it crashes or nothing at all. I have tried [[UINavigationController alloc] initWithRootViewController:navigationConroller]
with no success as well. I'm just using pushViewController
to try and place the next nib on the stack which doesn't work. What am I doing wrong?
Asked
Active
Viewed 4,943 times
2
-
You will probably won't get any responses until you post your code to show what you are doing. – coneybeare Oct 26 '09 at 05:11
1 Answers
10
Although there are a lot of people saying on forums that Apple doesn't allow this I have got it to work. What you have to do is:
Map *mapScreen = [[[Map alloc] init] autorelease];
mapScreen.delegate = self;
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:mapScreen] autorelease];
[self presentModalViewController:navController animated:YES];

Rudiger
- 6,749
- 13
- 51
- 102
-
This is the method I use as well, a UINavigationController is simply a subclass of a UIViewController, and you can do all the same things with it as you would do with a UIViewController. – Alex Gosselin Sep 07 '10 at 04:09
-
This is the technique that Apple describes in the View Controller Programming Guide for iOS: Modal View Controllers. Perhaps people were commenting on your unnecessary use of autorelease. When you use presentModalViewController: mapScreen and navController are both retained by self, and can be accessed through self.modalViewController, so you can and should release both right away. – Elise van Looij Dec 23 '10 at 12:21
-
Huh? its just the example, I don't use autorelease normally but just for easy of the example I put it here as autorelease, means people know that it should be released. This is also very old and most forums at the time said you couldn't do it, hence the first statement in the answer. – Rudiger Dec 23 '10 at 22:25