3

我用来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];
}
4

2 回答 2

3

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

-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    [self dismissViewControllerAnimated:YES completion:nil];
}
于 2013-07-05T07:15:13.773 回答
0

尝试这个

[self presentModalViewController:mailer animated:YES];  

解雇

[self dismissModalViewControllerAnimated:YES];
于 2013-07-05T07:30:04.910 回答