Reputation: 3206
My rootviewcontroller in my iPad app presents a modal viewcontroller through [self presentModalViewController:... animated:YES]
(lets call it ViewControllerA).
At some point, ViewControllerA itself presents a MFMailComposeViewController
via [self presentModalViewController:... animated:YES]
.
In the delegate method mailComposeController:didFinishWithResult:error:
I want to dismiss BOTH of the controllers, the MFMailComposeViewController
AND ViewControllerA.
But no matter what i try ([self.parentViewController dismissModalViewControllerAnimated:YES]
, [self dismissModalViewControllerAnimated:YES]
, calling dismiss twice), ONLY the MFMailComposeViewController
is dismissed, but ViewControllerA stays visible.
I already found this post (http://stackoverflow.com/questions/3229755/dismissing-multiple-modal-view-controllers-at-once) and this post (http://stackoverflow.com/questions/3105855/how-to-move-to-first-viewcontroller-from-last-view-controller-among-multiple-vie), but the suggested solutions don't seem to work for me.
What am I doing wrong?
Upvotes: 0
Views: 1003
Reputation: 912
I had the same problem dismissing multiple modal views.
Probably you are getting the warning:
Attempt to dismiss from view controller while a presentation or dismiss is in progress
The solution is to dismiss the first view without animation and then dismiss the other one. The last one can be dismissed using animation, there's no problem.
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
switch (result) {
case MFMailComposeResultSent:
[self dismissModalViewControllerAnimated:NO];
if (![[self modalViewController] isBeingDismissed])
[self dismissModalViewControllerAnimated:YES];
default:
break;
}
}
Upvotes: 1