2010-11-05 50 views
4

关闭我提出的电子邮件时遇到困难。iPhone:如何关闭MFMailComposeViewController?

电子邮件打开很好,但一旦打开,它将不会像mailComposeController一样关闭:邮件程序didFinishWithResult:result error:错误处理程序永远不会被调用。

据我可以告诉我,所有的位都可以做到这一点。

任何我能看到的任何想法?

这是我如何提高电子邮件:

-(IBAction)emailButtonPressed 
{ 

的NSString *文本= @ “我的电子邮件文本”;

MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init]; 
mailer.delegate = self; 

[mailer setSubject:@"Note"]; 
[mailer setMessageBody:text isHTML:NO]; 
[self presentModalViewController:mailer animated:YES]; 
[mailer release]; 
} 

,后来在课堂上,我有这样的代码来处理关闭(但它永远不会被调用):

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

我的头文件中被定义为:

#import <UIKit/UIKit.h> 
#import <MessageUI/MessageUI.h> 
#import <MessageUI/MFMailComposeViewController.h> 

@interface myViewController : UIViewController <UIActionSheetDelegate, UIAlertViewDelegate, MFMailComposeViewControllerDelegate, UINavigationControllerDelegate> 

谢谢

Iphaaw

回答

10

要设置委托错了,MFMailComposeViewController委托属性被称为mailComposeDelegate,所以它应该是:

mailer.mailComposeDelegate = self; 

另一种可能的错误,我可以看到的是在mailer调用dismissModalViewControllerAnimated: - 你应该把这个消息给视图控制器

[self dismissModalViewControllerAnimated:YES]; 

我写了“可能出现的错误”,因为如果iOS的路线通过响应链的消息,反正它实际上可能工作 - 文件说,它应该被发送到主持人:在这种情况下self - 谁提供的邮件界面。

+0

谢谢 - 修复它。看起来像我的书是错的:-( – iphaaw 2010-11-06 16:44:26

+0

也谢谢 - 我有同样的问题(不断认为这是我自我声明自我弱,原来是代表安装线!):) – 2014-07-03 15:10:23