无法关闭 MFMailComposeViewController,未调用委托
我正在从 UITableViewController
调用 MFMailComposeViewController
。 问题是当我在邮件撰写窗口中选择取消或发送按钮时,永远不会调用委托方法:
mailComposeController:(MFMailComposeViewController*)controllerdidFinishWithResult
这是表视图类:
@implementation DetailsTableViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section==0 && indexPath.row==4) {
//SEND MAIL
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
[controller setSubject:[NSString stringWithFormat:@"Ref %@",[item objectForKey:@"reference"]]];
[controller setMessageBody:@" " isHTML:NO];
[controller setToRecipients:[NSArray arrayWithObject:[item objectForKey:@"email"]]];
[self presentModalViewController:controller animated:YES];
}
[controller release];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controllerdidFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
// NEVER REACHES THIS PLACE
[self dismissModalViewControllerAnimated:YES];
NSLog (@"mail finished");
}
应用程序不会崩溃。按下“取消”或“发送”按钮后,撰写窗口将保留在屏幕上,并且按钮被禁用。我可以按主页键退出应用程序。
我可以从 TableView 打开其他模态视图,但不能打开 MailCompose。
I am calling MFMailComposeViewController
from a UITableViewController
.
Problem is the delegate method is never called when I select Cancel or Send button in Mail compose window:
mailComposeController:(MFMailComposeViewController*)controllerdidFinishWithResult
Here is the table view class:
@implementation DetailsTableViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section==0 && indexPath.row==4) {
//SEND MAIL
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
[controller setSubject:[NSString stringWithFormat:@"Ref %@",[item objectForKey:@"reference"]]];
[controller setMessageBody:@" " isHTML:NO];
[controller setToRecipients:[NSArray arrayWithObject:[item objectForKey:@"email"]]];
[self presentModalViewController:controller animated:YES];
}
[controller release];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controllerdidFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
// NEVER REACHES THIS PLACE
[self dismissModalViewControllerAnimated:YES];
NSLog (@"mail finished");
}
The application doesn't crash. After the Cancel or Send button is pressed, the Compose Window stays on the screen with buttons disabled. I can exit application pressing Home key.
I am able to open other Modal Views form TableView but not MailCompose.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
确保您使用
和不使用
Make sure you use
and not
您的方法签名不正确:
应该是:
Your method signature is incorrect:
Should be:
请参阅本文以了解完整实施:http://www.ioscreator.com/ tutorials/send-email-from-an-app工作代码:
删除已弃用的代码后,
Refer this article for full implementation : http://www.ioscreator.com/tutorials/send-email-from-an-app
working code after making removing deprecated one :
我遇到了同样的问题,过去两天一直在寻找解决方案,然后我自己找到了一个解决方案,你不会相信它有多么小。
就我而言,我呈现 MFMailComposeViewController 的视图控制器(按照这个问题说“DetailsTableViewController”)已经从其他视图控制器(比如“BaseViewController”)呈现。
问题在于从 BaseViewController 呈现“DetailsTableViewController”的“
modalPresentationStyle
”。当我将其从“
UIModalPresentationFormSheet
”更改为“UIModalPresentationPageSheet
”(就此而言,除“UIModalPresentationFormSheet
”之外的任何内容)问题得到解决并且邮件控制器委托方法开始像往常一样触发。注意:我已经在“DetailsTableViewController”中调用了以下方法(对于本例),因此使用哪个“
modalPresentationStyle
”对我来说并不重要。I faced the same problem and was searching for a fix from past 2 days then I found a fix myself and you won't believe how minor it was.
In my case the view controller (say 'DetailsTableViewController' as per this question) from where I was presenting the
MFMailComposeViewController
is already being presented from some other view controller (say 'BaseViewController').The issue was lying in the '
modalPresentationStyle
' of 'DetailsTableViewController' while presenting it from BaseViewController.The moment I changed it from '
UIModalPresentationFormSheet
' to 'UIModalPresentationPageSheet
' (for that matter any thing other than 'UIModalPresentationFormSheet
') issue got resolved and mail controller delegate methods started firing as usual.Note: I was already calling the below method in 'DetailsTableViewController' (for this example) so it didn't really matter for me which '
modalPresentationStyle
' I was using.