IPhone: how to close MFMailComposeViewController?

I'm having difficulty closing the email message that I picked up.

E-mail opens beautifully, but after it is opened it will not be closed, because mailComposeController: mailer didFinishWithResult: result error: the error handler is never called.

As far as I can tell, I have all the bits to be able to do this.

Any ideas on what I can look at?

Here's how I put up an 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 then in the class I have this code to handle closing (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

Ifaaw

+4
source share
1 answer

You have configured the delegate incorrectly, the delegate property in MFMailComposeViewController is called mailComposeDelegate, so it should be:

 mailer.mailComposeDelegate = self; 

Another possible error that I see is causing dismissModalViewControllerAnimated: on mailer - you must send this message to the view controller that introduced the mail interface - self in this case:

 [self dismissModalViewControllerAnimated:YES]; 

I wrote a “possible mistake” because it really can work if iOS sends a message through a chain of responders, anyway - the documentation says that it should be sent to the host.

+10
source

All Articles