Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to dismiss MFMailComposeViewController, delegate not called

I am calling MFMailComposeViewController from a UITableViewController. Problem is the delegate method is never called when I select Cancel or Send button in Mail compose window:

mailComposeController:(MFMailComposeViewController*)controllerdidFinishWithResult  

Here is the table view class:

@implementation DetailsTableViewController - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {     if (indexPath.section==0 && indexPath.row==4) {         //SEND MAIL         MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];         controller.mailComposeDelegate = self;         if ([MFMailComposeViewController canSendMail]) {             [controller setSubject:[NSString stringWithFormat:@"Ref %@",[item objectForKey:@"reference"]]];             [controller setMessageBody:@" " isHTML:NO];              [controller setToRecipients:[NSArray arrayWithObject:[item objectForKey:@"email"]]];              [self presentModalViewController:controller animated:YES];         }         [controller release];            } }  - (void)mailComposeController:(MFMailComposeViewController*)controllerdidFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {     // NEVER REACHES THIS PLACE     [self dismissModalViewControllerAnimated:YES];     NSLog (@"mail finished"); } 

The application doesn't crash. After the Cancel or Send button is pressed, the Compose Window stays on the screen with buttons disabled. I can exit application pressing Home key.

I am able to open other Modal Views form TableView but not MailCompose.

like image 331
Rod Avatar asked Dec 16 '09 23:12

Rod


2 Answers

Make sure you use

controller.mailComposeDelegate = self; 

and not

controller.delegate = self; 
like image 145
mxg Avatar answered Oct 04 '22 15:10

mxg


Your method signature is incorrect:

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

Should be:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
like image 28
Chris Gummer Avatar answered Oct 04 '22 15:10

Chris Gummer