[英]Trying to dismiss UIAlertController iOS 8
Crashlytics send me this error in my app: Crashlytics在我的应用程序中发送此错误:
Fatal Exception: NSInternalInconsistencyException
Trying to dismiss UIAlertController <UIAlertController: 0x14de40020> with unknown presenter.
UIKit
-[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:] + 584
This problem only occurs in iOS 8 but when I try to reproduce this error, my alertViews
work correctly in iOS 8 and nothing bad happens. 此问题仅发生在iOS 8中,但当我尝试重现此错误时,我的
alertViews
在iOS 8中正常工作,没有任何不好的事情发生。 Why this problem is happening? 为什么会出现这个问题?
I have read that in iOS 8 UIAlertView
is deprecated and now, we have to use UIAlertController
but when I try to use UIAlertController I can't dismiss the alert and the functionality is not the same. 我已经读过在iOS 8中
UIAlertView
已被弃用,现在我们必须使用UIAlertController
但是当我尝试使用UIAlertController时,我无法忽略警报并且功能不一样。
Please help me. 请帮我。
Thank you for advance. 谢谢你提前。
EDIT: 编辑:
The code I want to change is this: 我想改变的代码是这样的:
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];
Replace this 替换它
[self presentModalViewController: navControl animated: YES];
[alerta dismissWithClickedButtonIndex:0 animated:YES];
With this 有了这个
[alerta dismissWithClickedButtonIndex:0 animated:YES];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self presentModalViewController: navControl animated: YES];
}];
This presents a new controller asynchronously to make sure the alert view is dismissed 这将异步提供一个新控制器,以确保取消警报视图
Not sure if you were able to solve this, but I had a similar issue and here is a potential solution: 不确定你是否能够解决这个问题,但我遇到了类似的问题,这是一个潜在的解决方案:
Implement the UIAlertViewDelegate Protocol and override the alertView:didDismissWithButtonIndex: method. 实现UIAlertViewDelegate协议并覆盖alertView:didDismissWithButtonIndex:方法。
Any presenting or dismissing of view controllers should occur within this method to be 100% sure that the the AlertView is completely dismissed before we navigate elsewhere and the "presenter" becomes unknown. 在我们导航到其他地方并且“演示者”变得未知之前,任何呈现或解除视图控制器都应该在此方法中100%确定AlertView完全被解除。
You can also do this when navigating from a UIActionSheet button click. 您也可以在从UIActionSheet按钮单击导航时执行此操作。
Set popoverPresentationController
for UIAlertController
设置
popoverPresentationController
为UIAlertController
Use like this code : 像这样的代码使用:
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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.