Trying to dismiss UIAlertController iOS 8

Crashlytics are sending me this error in my application:

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, mine alertViews

works correctly in iOS 8 and nothing bad happens. Why is this problem happening?

I read that it is UIAlertView

deprecated in iOS 8 and now we have to use UIAlertController

, but when I try to use the UIAlertController I cannot cancel the warning and the functionality is not the same.

Please help me.

Thank you for your promotion.

EDIT:

The code I want to change is the following:

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

      

+3


source to share


3 answers


Replace this

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

      

With the help of this



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

      

This introduces a new controller asynchronously to make sure the warning is disabled

+3


source


Not sure if you were able to solve this, but I had a similar problem and here is a potential solution:

Implement a protocol UIAlertViewDelegate and override alertView: didDismissWithButtonIndex method: .



Any views or rejections of view controllers must have it inside so that this method is 100% sure that the AlertView is completely fired before we move elsewhere and the "presenter" becomes unknown.

You can also do this while navigating with the UIActionSheet button.

+1


source


Set popoverPresentationController

forUIAlertController

Use 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];

      

0


source







All Articles