Coocoo4Cocoa
Coocoo4Cocoa

Reputation: 50916

iPhone: Popping a modalViewController off of a UINavigationController stack

Ever since I've taken one of my UIViewController subclasses and present it to the user in the form of a modal view, with presentModalViewController:animated.. I haven't been able to dismiss it using:

[self dismissModalViewControllerAnimated:YES];

I do believe this is some odd mixup with how I'm instantiating a UINavigationController on the modalViewController, with code that looks like the following (similar code is also in the App Delegate):

UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
navigationController =
    [[UINavigationController alloc] initWithRootViewController:self];
navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
[window addSubview:navigationController.view];
[window makeKeyAndVisible];

The navigation stack works as expected, but unless I remove it, I can't dismiss the modal view controller any longer. I'm under the impression that I shouldn't be adding a subView to UIWindow more than once and that's just one of the problems.

Upvotes: 0

Views: 123

Answers (1)

Marc Novakowski
Marc Novakowski

Reputation: 45408

Make sure you call dismissModalViewControllerAnimated on the parent of the modal view controller, not on the modal view controller itself.

Upvotes: 1

Related Questions