【问题标题】:iPhone: How to Close MFMailComposeViewController?iPhone:如何关闭 MFMailComposeViewController?
【发布时间】:2010-11-05 07:43:38
【问题描述】:

我在关闭我提出的电子邮件时遇到了困难。

电子邮件可以很好地打开,但是一旦打开它就不会关闭,因为 mailComposeController:mailer didFinishWithResult:result error: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];
 [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>

谢谢

伊帕奥

【问题讨论】:

    标签: iphone objective-c email delegates


    【解决方案1】:

    你设置的delegate不对,MFMailComposeViewController中的delegate属性叫做mailComposeDelegate,所以应该是:

    mailer.mailComposeDelegate = self;
    

    我可以看到的另一个可能的错误是在mailer 上调用dismissModalViewControllerAnimated: - 您应该将此消息发送给呈现邮件界面的视图控制器 - 在这种情况下为self

    [self dismissModalViewControllerAnimated:YES];
    

    我写了“可能的错误”,因为如果 iOS 通过响应者链路由消息,它实际上可能会起作用 - 文档说它应该发送给演示者。

    【讨论】:

    • 也谢谢 - 我遇到了同样的问题(一直认为这是我将自己声明为弱自我,结果是委托设置行!):)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多