MFMailComposeViewController不会解散

时间:2013-07-05 07:03:02

标签: iphone mfmailcomposeviewcontroller dismiss

我使用MFMailComposeViewController向其他人发送邮件。单击按钮时,撰写工作表正在打开,我可以键入“地址”,“主题”,“邮件正文”。但是在点击发送按钮后,邮件页面没有关闭。

代码:

if ([MFMailComposeViewController canSendMail])
{
    MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
    mailer.mailComposeDelegate = self;
    [mailer setSubject:@"My image"];


    UIImage *myImage = [UIImage imageNamed:@"mobiletuts-logo.png"];
    NSData *imageData = UIImagePNGRepresentation(myImage);           


    [mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"Image"];
    NSString *emailBody = @"Hi, my image";
    [mailer setMessageBody:emailBody isHTML:NO];          

    [self presentViewController:mailer animated:YES completion:nil];
 } 

- (void)mailComposeController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    switch (result) {
        case MFMailComposeResultCancelled:
            break;
        case MFMailComposeResultSent:
            break;
        default:
            break;
    }

   [self dismissViewControllerAnimated:YES completion:nil];
}

2 个答案:

答案 0 :(得分:2)

对不起。忘记添加这些行。在这之后邮件工作

-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    [self dismissViewControllerAnimated:YES completion:nil];
}

答案 1 :(得分:0)

试试这个

[self presentModalViewController:mailer animated:YES];  

解雇

[self dismissModalViewControllerAnimated:YES];