MFMailComposeViewController's delegate not handling the CANCEL button

user628896 picture user628896 · Nov 29, 2011 · Viewed 9.1k times · Source

Possible Duplicate:
Action sheet doesn't display when the MFMailComposeViewController's cancel button is tapped

I've implemented standard mail functionality in my app according to the code sample provided by Apple.

I'm setting up the delegate as follows:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

and I'm implementing

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 

Hitting the Send button invokes the delegate and it all works fine. However, hitting the Cancel button doesn't call the delegate and it just dims the view; the app hangs right there.

After reading similar threads here, I've been thinking that the view could be off-screen for some reason which is beyond my comprehension at this point. Note that the view is being created programmatically and is not using a xib file.

Any thoughts or ideas ?

Answer

Srikar Appalaraju picture Srikar Appalaraju · Nov 29, 2011

You need to implement mailComposeController:didFinishWithResult:error delegate. And in that you dismiss the view which is showing your mail view. If you have opened the mail view as a modalView, then the way to dismiss this is -

- (void)mailComposeController:(MFMailComposeViewController*)controller 
          didFinishWithResult:(MFMailComposeResult)result
                        error:(NSError*)error 
{ 
    if(error) NSLog(@"ERROR - mailComposeController: %@", [error localizedDescription]);
    [self dismissModalViewControllerAnimated:YES];
    return;
}