开发者

iPhone: How to Close MFMailComposeViewController?

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/Messa开发者_JAVA技巧geUI.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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜