iPhone电子邮件表单按钮不起作用

时间:2013-11-23 19:35:06

标签: ios objective-c email mfmailcomposeviewcontroller

这就是我的电子邮件表单的样子:

  

if([MFMailComposeViewController canSendMail]){

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

    [mail setSubject:@"Hello and welcome!"];

    NSArray *toRecipients = [NSArray arrayWithObject:@"email@gmail.com"];
    [mail setToRecipients:toRecipients];
    [mail setCcRecipients:toRecipients];

    NSString *emailBody = @"Hey all!";
    [mail setMessageBody:emailBody isHTML:NO];

    mail.modalPresentationStyle = UIModalPresentationPageSheet;
    [self presentViewController:mail animated:YES completion:nil];


} else {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!"
                                                    message:@"E-mail is not supported on your device"
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];
}

电子邮件发送正常,但问题是,一旦我按下发送按钮,电子邮件就会被发送,但是视图控制器(或弹出窗口)不会关闭。并且关闭按钮也不起作用。我根本无法从电子邮件表格中退出。

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

你可能没有打电话

  

dismissViewControllerAnimated

[self dismissViewControllerAnimated:YES
                         completion:nil];

使用它:

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

    switch (result) {
        case MFMailComposeResultCancelled:
            break;
        case MFMailComposeResultSaved:
            NSLog(@"mail saved");
            break;
        case MFMailComposeResultSent:
            NSLog(@"mail sent");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"mail failed");
            break;
    }
[self dismissViewControllerAnimated:YES
                         completion:nil];
}