Search code examples
iphonexcodeuitableviewmfmailcomposeviewcontroller

Show Mail Composer When Cell of Table View Is Selected


I am trying to get my table view to present a mailcomposerviewcontroller when a cell is selected. I have tried using:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;



// Set up recipients
if ([arryData objectAtIndex:0]) {
    [picker setSubject:@"To You"];

    NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"];
    [picker setToRecipients:toRecipients];

    // Fill out the email body text
    NSString *emailBody = @"From Me";
    [picker setMessageBody:emailBody isHTML:NO];

    [self presentModalViewController:picker animated:YES];
    [picker release];
}
}

Yet, this gets me a crash and

which is waiting for a delayed presention of <MFMailComposeViewController:

Solution

  • Your code snippet seems to be fine here. Still go through these steps again if you have missed something for that matter.

    http://www.roseindia.net/answers/viewqa/Mobile-Applications/18176-iPhone-MFMailcomposeviewcontroller-example.html

    I hope it helps you! Cheers!!