我有以下在didSelectRowAtIndexPath中调用的代码。问题是,当我单击取消按钮时,它会提示保存草稿或丢弃。但是当我点击其中任何一个时,视图都不会被忽略。我在之前的iOS 5应用程序中使用了相同的代码并且它被解雇了。有任何想法吗?我在界面中有MFMailComposeViewController委托协议。
if (indexPath.row == 0)
{
if([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Support"];
NSArray *toRecipients = [NSArray arrayWithObject:@"contact@app.com"];
[picker setToRecipients:toRecipients];
NSString *emailBody = text;
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
}
}
答案 0 :(得分:18)
使用:强>
dismissViewControllerAnimated:completion:
从IOS 6.0中弃写:
将此方法添加到您的班级:
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissModalViewControllerAnimated:YES];
}
玩得开心
答案 1 :(得分:9)
可能有几个问题:
不在.h
中添加协议实现@interface yourClass : UIViewController <MFMailComposeViewControllerDelegate>
不在.m:
中添加相关功能-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult: (MFMailComposeResult)result error:(NSError*)error {
[self dismissModalViewControllerAnimated:YES];
}
我的错误是没有设置正确的委托,但我修复了它:)现在它适用于我:
picker.mailComposeDelegate = self;
答案 2 :(得分:1)
“dismissModalViewControllerAnimated:”已弃用 iOS 6.0
iOS 7使用:
“dismissViewControllerAnimated:完成:”
答案 3 :(得分:0)
我已经在这里更详细地描述了问题以及可以解决的方式:https://stackoverflow.com/a/13576408/691660
我不确定Luda是否抓住了问题的核心。无论是否指定委托都没有区别,在模态+模态MFMailComposeViewController实例的情况下不起作用。
答案 4 :(得分:0)
Swift 实施:
确保每次执行其函数时都调用MFMailComposeViewController
协议和委托。
这解决了MFMailComposeViewController
未被解雇的问题。
let subj = "Test"
let messageBody = "Test"
let toRecipents = ["example@xyz.com"]
let mc: MFMailComposeViewController = MFMailComposeViewController()
mc.mailComposeDelegate = self
mc.setSubject(subj)
mc.setMessageBody(messageBody, isHTML: true)
mc.setToRecipients(toRecipents)
self.present(mc, animated: true, completion: nil)