【问题标题】:MFMailComposeViewController's delegate not handling the CANCEL button [duplicate]MFMailComposeViewController 的委托未处理取消按钮 [重复]
【发布时间】:2011-11-29 05:30:27
【问题描述】:

可能重复:
Action sheet doesn't display when the MFMailComposeViewController's cancel button is tapped

我已经根据 Apple 提供的代码示例在我的应用中实现了标准邮件功能。

我正在按如下方式设置委托:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

我正在实施

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 

点击发送按钮调用委托,一切正常。但是,点击取消按钮不会调用委托,它只会使视图变暗;该应用程序挂在那里。

在这里阅读了类似的帖子后,我一直认为该视图可能出于某种原因不在屏幕上,这超出了我目前的理解范围。请注意,视图是以编程方式创建的,并且不使用 xib 文件。

有什么想法或想法吗?

【问题讨论】:

  • 如果委托没有被要求取消,那么有人怀疑委托设置不正确,或者您以某种方式“破坏”了邮件控制器的环境,使其内部出现各种错误.

标签: iphone objective-c ios delegates mfmailcomposeviewcontroller


【解决方案1】:

您需要实现mailComposeController:didFinishWithResult:error 委托。并且您关闭了显示您的邮件视图的视图。如果您已将邮件视图作为 modalView 打开,那么关闭它的方法是 -

- (void)mailComposeController:(MFMailComposeViewController*)controller 
          didFinishWithResult:(MFMailComposeResult)result
                        error:(NSError*)error 
{ 
    if(error) NSLog(@"ERROR - mailComposeController: %@", [error localizedDescription]);
    [self dismissModalViewControllerAnimated:YES];
    return;
}

【讨论】:

    【解决方案2】:

    可能对你有帮助

    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
    {   
        // Notifies users about errors associated with the interface
        switch (result)
        {
            case MFMailComposeResultCancelled:
                //NSLog(@"Result: canceled");
                break;
            case MFMailComposeResultSaved:
                //NSLog(@"Result: saved");
                break;
            case MFMailComposeResultSent:
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result" message:@"Mail Sent Successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                [alert show];
                [alert release];
            }
                break;
            case MFMailComposeResultFailed:
                //NSLog(@"Result: failed");
                break;
            default:
                //NSLog(@"Result: not sent");
                break;
        }
        [self dismissModalViewControllerAnimated:YES];
    }
    

    【讨论】:

      【解决方案3】:

      尝试添加更简单的委托:

      [picker setDelegate:self];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多