dismissViewControllerAnimated:不起作用

dismissViewControllerAnimated: does not work

我有一种方法可以从我的 table 视图发送电子邮件。

所以其中一个单元格是 "contact us" 单元格,每当它被点击时,我都会使用 MFMailComposeViewController 进入邮件视图控制器,但问题是当我点击 "cancel"或者 "send" 我的邮件视图控制器没有返回到 table 视图。 "cancel" 和 "send" 操作有效,但我留在邮件视图控制器上。

这是相关方法:

- (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;
        }
    }
}

请帮忙,谢谢!!

mailComposeController 方法中像这样关闭它:

[controller dismissViewControllerAnimated:YES completion:NULL];