2
votes

I am getting following error when I try to present a UIViewController modally.

"Application tried to present modally an active controller".

I have read many posts on this in stackoverflow. Which explains about this error. I am aware that, this exception is thrown when UIViewController which is already presented, is attempted to show modally again.

My application logic is:

When app goes to background. I dismiss modal view controller using

[self dismissModalViewControllerAnimated:NO]

When app comes back to foreground, I show the controller again

[self presentModalViewController:viewController animated:NO]

This logic works fine on iPad with iOS 6.0.1, but fails with iPad Mini with iOS 6.0.2.

I appreciate any suggestions.

1
I changed the implementation to this: [self presentViewController:viewController animated:NO completion:nil]; [self dismissViewControllerAnimated:NO completion:nil]; Still same exception is generated. I checked the presentedViewController property, interestingly it still holds the reference to the view controller even after dismissing it.Vinay

1 Answers

0
votes

I think that the best solution is to use presentViewControllerAnimated:completion:nil and dismissViewControllerAnimated:completion: for iOS6 or try to present the view controller after some delay (Call by method of NSTimer).

[self presentViewController:YourVC animated:YES completion:nil];

and

[self dismissViewControllerAnimated:YourVC completion:nil];