4

可能重复:
Action sheet doesn't display when the MFMailComposeViewController's cancel button is tappedMFMailComposeViewController的委托不处理CANCEL按钮

我根据苹果提供的代码示例中我的应用程序中实现标准邮件功能。

我设立委托如下:

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

,我实现

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

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

这里阅读类似主题后,我一直在想,认为可能是关闭屏幕由于某种原因,这超出了我在这一点上理解。请注意,该视图是以编程方式创建的,并未使用xib文件。

任何想法或意见?

+0

犯罪嫌疑人的委托没有设置正确,或者你已经在某种程度上“破”的邮件控制器,使得它在内部采取各种错误的环境。 –

+0

您使用ARC吗? – Oscar

回答

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]; 
} 
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; 
} 
0

尝试添加甚至简单的委托:如果委托没有得到呼吁取消再一个

[picker setDelegate:self]; 
相关问题