iPhone:如何关闭MFMailComposeViewController? [英] iPhone: How to Close MFMailComposeViewController?
问题描述
电子邮件打开很好,但一旦打开它将不会像mailComposeController那样关闭:mailer didFinishWithResult:result error:错误处理程序永远不会被调用。
据我所知,我已经掌握了一切可以做到的一切。
任何人有什么想法可以看看?
这是我如何提高电子邮件:
- (IBAction)emailButtonPressed
{
NSString * text = @我的电子邮件文本;
MFMailComposeViewController * mailer = [[MFMailComposeViewController alloc] init];
mailer.delegate = self;
[mailer setSubject:@Note];
[mailer setMessageBody:text isHTML:NO];
[self presentModalViewController:mailer animated:YES];
[邮件发布];
}
后来在类中我有这个代码来处理关闭(但它永远不会被调用):
- (void)mailComposeController :( MFMailComposeViewController *)mailer didFinishWithResult:(MFMailComposeResult)结果错误:(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
您正在设置委托错误, MFMailComposeViewController
中的委托属性称为mailComposeDelegate,所以应该是:
mailer.mailComposeDelegate = self;
我可以看到的另一个可能的错误是调用 dismissModalViewControllerAnimated:
on mailer
- 您应该将此消息发送给呈现邮件界面的视图控制器 - self
在这种情况下:
[self dismissModalViewControllerAnimated:YES];
我写了可能的错误,因为如果iOS通过响应者链路由消息,实际上可能会起作用,无论如何 - 文件说应该发送给演示者。
I'm having difficulties closing an email message that I have raised.
The email opens nicely, but once it is opened it will not close as the mailComposeController:mailer didFinishWithResult:result error:error handler never gets invoked.
As far as I can tell I have all the bits in place to be able to do this.
Anyone any ideas of what I can look at?
Here is how I raise the email:
-(IBAction)emailButtonPressed
{
NSString *text = @"My Email Text";
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.delegate = self;
[mailer setSubject:@"Note"];
[mailer setMessageBody:text isHTML:NO];
[self presentModalViewController:mailer animated:YES];
[mailer release];
}
and later in the class I have this code to handle the close (but it never gets called):
-(void)mailComposeController:(MFMailComposeViewController *)mailer didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self becomeFirstResponder];
[mailer dismissModalViewControllerAnimated:YES];
}
My header file is defined as:
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
@interface myViewController : UIViewController <UIActionSheetDelegate, UIAlertViewDelegate, MFMailComposeViewControllerDelegate, UINavigationControllerDelegate>
Thanks
Iphaaw
You are setting the delegate wrong, the delegate property in MFMailComposeViewController
is called mailComposeDelegate, so it should be:
mailer.mailComposeDelegate = self;
Another possible error I can see is calling dismissModalViewControllerAnimated:
on mailer
- you should send this message to the view controller who presented the mail interface - self
in this case:
[self dismissModalViewControllerAnimated:YES];
I wrote "possible error" because it might actually work if iOS routes the message through responder chain, anyway - the documentation says it should be send to presenter.
这篇关于iPhone:如何关闭MFMailComposeViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!