6

我正在尝试截取屏幕截图并使用邮件编辑器通过电子邮件发送。一切都很好,除了邮件作曲家不会解雇。这篇文章似乎有同样的问题,但提供的解决方案对我不起作用。无法关闭 iPhone 中的电子邮件编辑器视图?

- (IBAction)Email:(id)sender {
UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

NSData * imageData = UIImageJPEGRepresentation(image, 1.0);

if ( [MFMailComposeViewController canSendMail] ) {
    MFMailComposeViewController * mailComposer = [[[MFMailComposeViewController alloc] init] autorelease];
    mailComposer.delegate = self;
    [mailComposer setSubject:@"Risk Assessment"];
    [mailComposer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment.jpg"];     
    [self presentModalViewController:mailComposer animated:YES];        
}
}

上面的代码效果很好。我如何称呼这个底部。似乎编译器只是跳过它。

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
if (error){
    NSString *errorTitle = @"Mail Error";
    NSString *errorDescription = [error localizedDescription];
    UIAlertView *errorView = [[UIAlertView alloc]initWithTitle:errorTitle message:errorDescription delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
    [errorView show];                
    [errorView release];
}
[controller dismissModalViewControllerAnimated:YES];

}

提前致谢。

4

2 回答 2

17

尝试

mailComposer.mailComposeDelegate = self;

代替

mailComposer.delegate = self;

MFMailComposeViewController 文档

@property(nonatomic,assign) id<MFMailComposeViewControllerDelegate> mailComposeDelegate;

委托对象负责在适当的时候关闭此视图控制器呈现的视图。因此,您应该始终提供一个委托,并且该对象应该实现 MFMailComposeViewControllerDelegate 协议的方法。

于 2012-07-11T14:30:37.407 回答
2

我很确定最后一行应该是

[self dismissModalViewControllerAnimated:YES];

以模态方式呈现视图的 ViewController 也会将其关闭。

于 2012-07-11T14:31:46.627 回答