2014-10-30 79 views
3

Crashlytics给我这个错误在我的应用程序:试图解雇UIAlertController的iOS 8

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

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

此问题仅出现在iOS 8的,但是当我试图重现这个错误,我alertViews iOS中8和没有正常工作坏事发生。为什么会出现这个问题?

我已经阅读,在iOS 8 UIAlertView已被弃用,现在,我们不得不使用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]; 

回答

0

UIAlertController

使用这样的代码设置popoverPresentationController

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

需要添加一个动作? – amurcia 2014-10-30 11:37:18

+0

这对我不起作用。当警报显示时,我更改了视图控制器并返回到mainVC。当我推送你的代码时,警报出现,但我无法推送de mainVC。 – amurcia 2014-10-30 11:41:09

1

不知道如果你能解决E本,但我也有类似的问题,这里是一个潜在的解决方案:

落实UIAlertViewDelegate协议和覆盖 alertView:didDismissWithButtonIndex:方法。

视图控制器的任何呈现或解聘应该发生内此方法,以确保100%的,在我们在别处导航和“演讲”变成未知的AlertView完全驳回。

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

3

替换此

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

有了这个

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

这就提出了一个新的控制器异步确保警报视图被驳回

+1

Xcode告诉我,presentModalViewController在iOS 6.0中不推荐使用,但是使用不同的方法(我有我的项目的内部)替换块中的行,它的工作。谢谢我已经投了答案。 :) – Gram 2015-07-02 22:28:42

+1

我知道弃用)。我刚刚编辑源代码行以使问题的答案更合适 – Tim 2015-07-03 10:40:16