问题
This turned out to be due to bug in iOS 8 beta. I have reported it via bug number 17318153
I'm setting an email address to a UITextField. The intent is for iOS to see its an email address and, if the user taps it, display an instance of MFMailComposeViewController to send an email (which it does).
However, if the user then taps cancel, the MFMailComposeViewController is not being dismissed. I tried setting my viewController as a MFMailComposeViewControllerDelegate and overriding mailComposeController: didFinishWithResult: error: but it's not being called. Seemingly, the delegate for the MFMailComposeViewController that is displayed when the url is tapped is not set to self.
How can I make the cancel button in the MFMailComposeViewController actually dismiss the view controller that is displayed?
My .h:
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@interface AboutUsViewController : UIViewController<MFMailComposeViewControllerDelegate>{
IBOutlet UIImageView *imageView;
IBOutlet UITextView *companyName;
IBOutlet UITextView *phoneNumber;
IBOutlet UITextView *emailAddress;
IBOutlet UITextView *aboutUsField;
}
@end
In .m:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
emailAddress.text=@"support@email.com";
}
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail sent failure: %@", [error localizedDescription]);
break;
default:
break;
}
// Close the Mail Interface
[self dismissViewControllerAnimated:YES completion:NULL];
}
回答1:
This is a known iOS8 beta 1 issue. Make sure to open a bug report with Apple and post the bug report number here so people can duplicate.
来源:https://stackoverflow.com/questions/24218708/cant-dismiss-mfmailcomposeviewcontroller-shown-by-clicking-mail-link-in-uitextvi