【问题标题】:MFMailComposeViewController dismiss issueMFMailComposeViewController 关闭问题
【发布时间】:2014-08-19 19:11:02
【问题描述】:

我在使用 MFMailComposeViewController 时遇到了一个奇怪的问题。我过去一直在使用 MFMailComposeViewController 没有任何问题,但现在我无法弄清楚这次出了什么问题,因此我希望得到您的帮助。

在我的应用程序中,我有多个 UIViewController,其中名为 MainViewController 的一个是 ViewController 容器,我在其中实现了左侧滑动菜单。在 MainViewController 中,我还添加了 UINavigationController。 UINavigationController 被分配并随后添加到 MainViewController 中,如下所示:

[self addChildViewController:self.navigationController];
[self.centerView addSubview:self.navigationController.view];
[self.navigationController didMoveToParentViewController:self];

上面的工作非常好,我可以使用导航控制器来推送和弹出其他 UIViewControllers。 在左侧菜单中,我有不同的按钮,其中一个名为“关于”。按下时会执行以下代码:

NSArray *array = [NSArray arrayWithObject:[AboutViewController sharedViewController]];
[self.navigationController setViewControllers:array animated:NO];

在 AboutViewController 中,我得到了一些按钮,其中一个是“发送反馈”。 “发送反馈”按钮执行以下代码:

if([MFMailComposeViewController canSendMail]) {
    MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
    mailer.mailComposeDelegate = self; 
    NSArray *toRecipients = [NSArray arrayWithObjects:[NSString stringWithFormat:@"feedback@test.com"], nil]; 
    [mailer setToRecipients:toRecipients]; 
    [mailer setSubject:[NSString stringWithFormat:@"Feedback"]];
    [self presentViewController:mailer animated:YES completion:nil]; 
}

这也有效。 AboutViewController 实现了 MFMailComposeViewControllerDelegate 及其方法:

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    switch (result) {
        case MFMailComposeResultCancelled:
            //NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
            break;
        case MFMailComposeResultSaved:
            //NSLog(@"Mail saved: you saved the email message in the drafts folder.");
            break;
        case MFMailComposeResultSent:
            //NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
            break;
        case MFMailComposeResultFailed:
            //NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
            break;
        default:
            //NSLog(@"Mail not sent.");
            break;
    }

    // Remove the mail view
    [self dismissViewControllerAnimated:YES completion:nil];
}

而这里让我头疼。我打电话给

[self dismissViewControllerAnimated:YES completion:nil];

就像我在以前的应用程序中所做的那样,它可以正常工作。但在这种情况下,MFMailComposeViewController 不会被解除,并且“取消”和“发送”按钮变为非活动状态。我试图在关闭完成块中实现一个 NSLog,但它从未被调用。

我搜索了几个小时,但找不到解决此问题的方法。我希望你能帮我解决这个奇怪的问题。如果您需要更多信息,请询问。

提前致谢。 - 塞巴斯蒂安

【问题讨论】:

  • 您的子视图控制器遇到了问题
  • 您必须调整子视图的大小
  • 我也有同样的问题,我解决了
  • 您能说得更具体一点吗?在导航控制器的分配中我做了以下操作:self.navigationController = [[UINavigationController alloc] init]; [self.navigationController setNavigationBarHidden:YES]; self.navigationController.view.frame = CGRectMake(0, 44, 320, [Utilities screenHeight] - 44); self.navigationController.delegate = self; self.navigationController.view.backgroundColor = [UIColor clearColor]; self.navigationController.navigationBar.translucent = NO;
  • 你是怎么解决的?

标签: ios objective-c iphone email uiviewcontroller


【解决方案1】:

您必须将邮件控制器打开到父视图控制器中。为此,您必须使用委托。 在您的父类中调用 MFMailComposeViewController 并通过自定义委托传递值

【讨论】:

  • 那么在MainViewController中?我试图将代码移到那里,但 MFMailComposeViewController 仍然没有关闭。
  • 你可以点击取消按钮吗?
  • 也许我不清楚我的问题。我可以按下取消按钮,这会调出操作表。当我按下删除草稿或保存草稿时,MFMailComposeViewController 不会关闭。按下发送按钮时也不会关闭。
  • 我想说 - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error 方法是否被调用?
  • 看起来它在dismiss调用中有点冻结,因为我在它下面添加了一个NSLog,它永远不会被执行。
【解决方案2】:

我设法解决了。我发现当 MainViewController 应该变得可见时,MainViewController 管理的线程之一在主线程中启动了一个无限循环。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-19
    相关资源
    最近更新 更多