2012-06-12 25 views
4

我想用MFMailComposeViewController發送郵件。當我點擊我的應用程序上的一個按鈕時發生。當然,當我單擊郵件控制器的取消按鈕時,我想回到我的應用程序視圖,但它不起作用。該怎麼辦 ?這裏是我的代碼:MFMailComposeViewController:取消不會退出到我的應用程序?

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init]; 
controller.mailComposeDelegate = self; 
[controller setSubject:@"Subject"]; 
[controller setMessageBody:@"<html>Test</html>" isHTML:YES]; 
[controller setToRecipients:nil]; 
if(controller) [self presentModalViewController:controller animated:YES]; 

感謝您的建議

回答

25

您已經實現了這個委託方法?這是在用戶退出作曲家之後調用的。

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

沒錯,非常感謝。 – Rob

+1

如果這對你是固定的,那麼你能接受答案嗎?謝謝。 – Damo

+2

dismissModalViewControllerAnimated 現在已被棄用,您應該使用 dismissViewControllerAnimated改爲 – alasker