2012-03-25 174 views
0

我已經在我的代碼中實現了MFMessageComposeViewController,但是現在我可以發送電子郵件了,當保存草稿,刪除它或甚至發送電子郵件時,視圖控制器不會被解僱。我也嘗試添加斷點,解除它的代碼甚至無法運行。MFMailComposeViewController沒有被解僱

- (IBAction)sendEmail:(id)sender { 

Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); 

if(mailClass != nil) 
{ 
    if ([mailClass canSendMail]) 
    { 
     [self displayComposerSheet]; 
    } 
    else 
    { 
     [self launchMailAppOnDevice]; 
    } 

} 
else 
{ 
    [self launchMailAppOnDevice]; 
} 
} 

- (void)displayComposerSheet 
{ 
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 

NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

[picker setEditing:YES]; 
[picker setToRecipients:toRecipients]; 

[self presentModalViewController:picker animated:YES]; 
picker.mailComposeDelegate = self; 
} 

- (void)launchMailAppOnDevice 
{ 
NSString *address = @"mailto:[email protected]"; 

NSString *email = [NSString stringWithFormat:@"%@", address]; 
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]]; 
} 

-(void)mailComposeController:picker didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
[self dismissModalViewControllerAnimated:YES]; 
} 

回答

0

嘗試在調用presentModalViewController之前設置委託。

0

嘗試在呈現模態視圖之前設置picker.mailComposeDelegate = self。 它可能會幫助你。

+0

我這樣做了,但無法將其設置爲回答。不管怎麼說,還是要謝謝你! – user1222053 2012-03-27 19:03:43