3

Crashlytics 在我的应用程序中向我发送此错误:

Fatal Exception: NSInternalInconsistencyException
Trying to dismiss UIAlertController <UIAlertController: 0x14de40020> with unknown presenter.

UIKit   
-[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:] + 584

此问题仅发生在 iOS 8 中,但是当我尝试重现此错误时,我alertViews在 iOS 8 中正常工作,并且没有发生任何不良情况。为什么会出现这个问题?

我已经读到在 iOS 8UIAlertView中已弃用,现在我们必须使用UIAlertController,但是当我尝试使用 UIAlertController 时,我无法解除警报,并且功能不一样。

请帮我。

谢谢你的提前。

编辑:

我要更改的代码是这样的:

UIAlertView * alerta = [[UIAlertView alloc] initWithTitle: AMLocalizedString(@"alertUpdate", @"")
                                                  message:@"\n"
                                                 delegate:self
                                        cancelButtonTitle:nil
                                        otherButtonTitles:nil];

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.center = CGPointMake(139.5, 75.5); // .5 so it doesn't blur
[alerta addSubview:spinner];
[spinner startAnimating];
[alerta show];


UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:dis bundle:nil];
MainVC *main = [storyBoard instantiateViewControllerWithIdentifier:@"MainVC"];
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: main];
[self presentModalViewController: navControl animated: YES];

[alerta dismissWithClickedButtonIndex:0 animated:YES];
4

3 回答 3

3

替换这个

[self presentModalViewController: navControl animated: YES];
[alerta dismissWithClickedButtonIndex:0 animated:YES];

有了这个

[alerta dismissWithClickedButtonIndex:0 animated:YES];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
    [self presentModalViewController: navControl animated: YES];
}]; 

这会异步呈现一个新控制器,以确保关闭警报视图

于 2015-03-30T09:46:39.637 回答
1

不确定您是否能够解决此问题,但我遇到了类似的问题,这是一个潜在的解决方案:

实现UIAlertViewDelegate 协议并覆盖 alertView:didDismissWithButtonIndex:方法。

视图控制器的任何呈现或关闭都应此方法中发生,以 100% 确保 AlertView 在我们导航到其他地方之前完全关闭,并且“演示者”变得未知。

您也可以在从 UIActionSheet 按钮单击导航时执行此操作。

于 2014-11-11T20:10:25.273 回答
0

设置popoverPresentationControllerUIAlertController

像这样使用代码:

UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"Title"
                                                                                  message: nil
                                                                           preferredStyle: UIAlertControllerStyleActionSheet];
        [alertController addAction: [UIAlertAction actionWithTitle: @"title" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

        }]];
CGRect rect = self.view.frame;
 rect.origin.x = self.view.frame.size.width / 20;
 rect.origin.y = self.view.frame.size.height / 20;
[alertController.popoverPresentationController setPermittedArrowDirections:0];
alertController.popoverPresentationController.sourceView = self.view;
alertController.popoverPresentationController.sourceRect = rect;
[alertController setModalPresentationStyle:UIModalPresentationPopover];
[self presentViewController: alertController animated: YES completion: nil];
于 2014-10-30T09:40:14.660 回答