原来这是由于 iOS 8 beta 中的错误。我已通过错误号 17318153 报告了它
我正在为 UITextField 设置一个电子邮件地址。目的是让 iOS 看到它的电子邮件地址,如果用户点击它,则显示 MFMailComposeViewController
的实例以发送电子邮件(它确实这样做了)。
但是,如果用户随后点击取消,则不会关闭 MFMailComposeViewController
。我尝试将我的 viewController 设置为 MFMailComposeViewControllerDelegate
并覆盖 mailComposeController: didFinishWithResult: error:
但它没有被调用。看起来,点击 url 时显示的 MFMailComposeViewController 的委托(delegate)未设置为 self。
如何让 MFMailComposeViewController
中的取消按钮真正关闭显示的 View Controller ?
我的.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
在 .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];
}
最佳答案
这是一个已知的 iOS8 beta 1 问题。确保打开 Apple 的错误报告并在此处发布错误报告编号,以便人们可以复制。
关于ios - 无法关闭通过单击 UITextVIew 中的邮件链接显示的 MFMailComposeViewController(iOS 8 测试版错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24218708/