Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIAlertView warning when dismissing

I'm creating an alert in the following manner:

let alert = UIAlertView(title: "Network Unavailable",
                      message: "Oh noes!",
                     delegate: nil,
            cancelButtonTitle: "OK")
alert.show()

Works fine. However when I click the 'OK' button to dismiss the alert, I get this:

Warning: Attempt to dismiss from view controller <_UIAlertShimPresentingViewController: 0x16ea2230> while a presentation or dismiss is in progress!

Some context:

  1. The alert is created in didMoveToView(view: SKView!) function of an SKScene.
  2. This is in Xcode 6 beta 3.
  3. my example is swift but this also happens from Objective-C

Any ideas why this warning might be occurring? I don't want to ignore it in case it turns into a fatal error in a future version of iOS.

UPDATE

I should also add that when the alert appears, when I select Debug -> View Debugging -> Capture View Hierarchy, the alert is not shown in the 3d view of the views. I'm wondering if this is symptomatic of something I'm doing wrong.

like image 408
Pinxaton Avatar asked Jul 14 '14 23:07

Pinxaton


1 Answers

I was getting the same warning:

Warning: Attempt to dismiss from view controller <_UIAlertShimPresentingViewController:> while a presentation or dismiss is in progress!

In iOS8, UIAlertController replaces UIAlertView. This should resolve your warning (in Objc):

UIAlertController *alert =
  [UIAlertController alertControllerWithTitle:@"Network Unavailable"
                                      message:@"Oh noes!"
                               preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *cancelAction =
  [UIAlertAction actionWithTitle:@"Ok"   
                           style:UIAlertActionStyleCancel
                         handler:^(UIAlertAction *action) {
                                                        }];
[alert addAction:cancelAction];    
[self presentViewController:alert animated:YES completion:nil];

See the documentation for UIAlertController for more info.

like image 117
dianna Avatar answered Sep 17 '22 14:09

dianna