0

我有UIAlertController。点击确定,显示MFMailComposeViewController。点击电子邮件撰写屏幕上的取消按钮,我解雇了MFMailComposeViewControllerMFMailComposeViewController的委托方法在解散时被正确调用。 MFMailComposeViewController成功解散。紧接着,如果我再次尝试相同的功能(流程)。我没有得到警觉,而是越来越低于错误。可能是什么原因?我尝试了大部分可用的解决方案。仍然遇到同样的问题。先显示UIAlertController,然后显示MFMailComposeViewController。只有第一次作品

试图提出< UIAlertController:上< MFMailComposeViewController 0x13890beb0>:0x1371ef000>谁的观点是不是在窗口层次**

我使用self presentViewController呈现alertcontroller和MFMailComposeViewController

示例代码是在这里:

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(nullable NSError *)error{ 
    [controller dismissViewControllerAnimated:YES completion: nil]; 


} 


UIAlertController * alertController= [UIAlertController alertControllerWithTitle:@"Title" message:@"message"     preferredStyle:UIAlertControllerStyleAlert]; 

    UIAlertAction* ok = [UIAlertAction 
         actionWithTitle:@"Ok" 
         style:UIAlertActionStyleDefault 
         handler:^(UIAlertAction * action) 
         { 
          [alertController dismissViewControllerAnimated:YES completion:nil]; 

          MFMailComposeViewController *mailComposerVC = [MFMailComposeViewController new]; 

          mailComposerVC.mailComposeDelegate = self; 

          if ([MFMailComposeViewController canSendMail]) { 


           [self presentViewController:(MFMailComposeViewController*)mailComposerVC animated: true completion: nil]; 
          } 

         }]; 
    UIAlertAction* cancel = [UIAlertAction 
          actionWithTitle:@"Cancel" 
          style:UIAlertActionStyleDefault 
          handler:^(UIAlertAction * action) 
          { 
           [alertController dismissViewControllerAnimated:YES completion:nil]; 

          }]; 

    [alertController addAction:ok]; 
    [alertController addAction:cancel]; 

    [self presentViewController:alertController animated:false completion:nil]; 
+1

更新与相关的代码你的问题。 – rmaddy

+1

你可以请张贴一些代码吗?并决定您是使用Swift还是Objective-C – FelixSFD

+1

http://stackoverflow.com/a/25864182/988769 – Kreiri

回答

0

很难说什么也正是导致问题。我发现了一些可能的原因,希望能解决其中的一个问题,最终将解决您的问题。

您应该在呈现的视图控制器上不要打电话给dismissViewControllerAnimated:。即使它通常有效,在你的情况下它可能会制动一些东西。你有3个地方你做错了。这就是其中之一:

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(nullable NSError *)error 
{ 
    [self dismissViewControllerAnimated:YES completion:nil]; // `controller` is replaces with `self` 
} 

而且你不应该被解雇alertController前出示mailComposerVC。你可以为此使用完成块。

你在模拟器上测试吗? MFMailComposeViewController在那里无法正常工作。尝试在真实设备上运行,也许,崩溃会神奇消失。

1

请使用下面的代码来呈现邮件控制器:

UIAlertController * alertController= [UIAlertController alertControllerWithTitle:@"Title" message:@"message"     preferredStyle:UIAlertControllerStyleAlert]; 

UIAlertAction* ok = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { 
         [alertController dismissViewControllerAnimated:YES completion:nil]; 

         MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init]; 

         mailComposerVC.mailComposeDelegate = self; 

         if ([MFMailComposeViewController canSendMail]) { 

          [[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:mailComposerVC 
                          animated:YES 
                          completion:nil]; 

         } 

        }]; 
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { 
          [alertController dismissViewControllerAnimated:YES completion:nil]; 

         }]; 

[alertController addAction:ok]; 
[alertController addAction:cancel]; 

[self presentViewController:alertController animated:false completion:nil]; 
+0

以上代码行是按钮操作的一部分。我的要求是,在显示电子邮件作曲者之前显示警报。 – user516542