2012-07-11 25 views
6

Tôi đang cố chụp ảnh màn hình và gửi email bằng trình soạn thư. Mọi thứ đều hoạt động tốt ngoại trừ nhà soạn thư sẽ không bỏ qua. Bài đăng này dường như có cùng một vấn đề, nhưng giải pháp được cung cấp không hoạt động đối với tôi. Can't dismiss the email composer view in iPhone?iOS Mail Composer sẽ không loại bỏ

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

Mã trên hoạt động rất tốt. Làm thế nào để tôi gọi phần dưới cùng này. Có vẻ như trình biên dịch chỉ bỏ qua nó.

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

} 

Xin cảm ơn trước.

Trả lời

17

Hãy thử

mailComposer.mailComposeDelegate = self; 

thay vì

mailComposer.delegate = self; 

Từ MFMailComposeViewController documentation:

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

Đối tượng đại biểu có trách nhiệm gạt bỏ quan điểm được trình bày bởi bộ điều khiển quan điểm này tại thời điểm thích hợp. Vì vậy, bạn nên luôn luôn cung cấp một đại biểu và đối tượng đó nên thực hiện các phương thức của giao thức MFMailComposeViewControllerDelegate.

+0

Cảm ơn bạn đã phản hồi nhanh. Điều này làm việc. – talbright

+0

Rất thú vị. Không bao giờ thấy điều đó. –

+0

Làm việc theo nghĩa đen trong nhiều giờ để tìm ra vấn đề của tôi, và điều này đã sửa nó! – Mark

2

Tôi khá chắc chắn rằng dòng cuối cùng nên

[self dismissModalViewControllerAnimated:YES]; 

Các ViewController rằng trình bày modally xem, cũng phủ nhận nó.

+0

Đúng vậy, cách anh ấy viết cũng nên hoạt động, nhưng cách ưu tiên là cách bạn mô tả [Tài liệu Apple về loại bỏ] (http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ ModalViewControllers.html # // apple_ref/doc/uid/TP40007457-CH111-SW14) – Bersaelor

Các vấn đề liên quan