Search code examples
ios6presentmodalviewcontroller

Nested modal view controller gives strange message under iOS6?


I am presenting a modal view controller from another modal view controller, and this worked fine under all iOS versions prior to iOS6. But under iOS6 I am getting the following warning message in the emulator:

Warning: Attempt to present <UINavigationController: 0x14e93680> on <UINavigationController: 0x9fc6b70> while a presentation is in progress!

The modal view controller is not shown if this warning appears. Basically I am using code like this to show the modal view controller:

WebAuthViewController *authController = [[WebAuthViewController alloc] initWithNibName:nil bundle:nil];
authController.challenge = challenge;
authController.delegate = self;
UINavigationController *aNavController = [[UINavigationController alloc] initWithRootViewController:authController];
[self presentModalViewController:aNavController animated:YES];
[aNavController release];
[authController release];

The view that is already shown is a UIWebView also shown in a modal view, like this:

WebViewController *addController = [[WebViewController alloc] initWithNibName:nil bundle:nil];
addController.urlToLoad = [NSURL URLWithString:urlString];
addController.delegate = self;

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];
navigationController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navigationController animated:YES];

[navigationController release];
[addController release];

The apple docs still suggest that one is supposed to be able to stack navigation controllers like this, so I am at a loss to explain why this happens. Any hints?


Solution

  • A view controller can only present a single view controller. This might have been allowed before, but is probably enforced in iOS6 due to an internal reorganization (presentModalViewController:animated: is deprecated in iOS6). It's time to change your organization of view controllers. Perhaps it is possible to introduce a navigation controller which is to be presented. If there is already a presented view controller, push your next one to the navigation stack.