我有一种从表格视图发送电子邮件的方法。
所以其中一个单元格是“联系我们”单元格,无论何时单击它我都会使用MFMailComposeViewController
进入邮件视图控制器,但问题是当我点击“取消”或“发送”我的邮件视图控制器不会返回到表视图。 “取消”和“发送”操作有效,但我留在邮件视图控制器上。
这是相关的方法:
- (void)sendEmail {
// Email Subject
NSString *emailTitle = @"Test Email";
// Email Content
NSString *messageBody = @"iOS programming is so fun!";
// To address
NSArray *toRecipents = [NSArray arrayWithObject:@"kkk@gmail.com"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:NO];
[mc setToRecipients:toRecipents];
// Present mail view controller on screen
[self presentViewController:mc animated:YES completion:NULL];
}
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail sent failure: %@", [error localizedDescription]);
break;
default:
break;
}
// Close the Mail Interface
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
SettingsControllerSection section = indexPath.section;
if (OtherControllerSection == section) {
SettingsControllerOtherSection row = indexPath.row;
switch (row) {
case RateUsController:
NSLog(@"rate us was pressed");
break;
case ContactUsControllerRow:
[self sendEmail];
NSLog(@"send email was pressed");
break;
}
}
}
请帮助,谢谢!!
答案 0 :(得分:2)
在mailComposeController
方法中忽略它:
[controller dismissViewControllerAnimated:YES completion:NULL];