MFMailComposeViewController的委托不处理CANCEL按钮

use*_*896 4 iphone delegates objective-c ios mfmailcomposeviewcontroller

可能重复:
点击MFMailComposeViewController的取消按钮时不显示操作表

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

我正在设置代表如下:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
Run Code Online (Sandbox Code Playgroud)

而我正在实施

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
Run Code Online (Sandbox Code Playgroud)

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

在这里阅读了类似的主题后,我一直认为视图可能因为某种原因而在屏幕外,这在我看来是无法理解的.请注意,该视图是以编程方式创建的,并未使用xib文件.

有什么想法或想法吗?

Sri*_*aju 9

您需要实现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;
}
Run Code Online (Sandbox Code Playgroud)


Ten*_*kar 8

它可能对您有所帮助

- (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];
}
Run Code Online (Sandbox Code Playgroud)