12

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.

JOM
  • 8,139
  • 6
  • 78
  • 111
Pinxaton
  • 437
  • 4
  • 13
  • 2
    Why **obviously** in Swift?! I personally think Swift is one of the most confusing, irritating and bad designed languages I've ever read... Nevertheless, I have the same issue and think this still might be a bug! Mind we're still in beta! – Julian F. Weinert Jul 15 '14 at 12:34
  • @Julian - "obviously in swift" because the code example is swift not because the bug only manifests in Swift. OP is obviously concerned its a swift bug. – Rog Jul 15 '14 at 15:08
  • 1
    Have you tried these solutions: http://stackoverflow.com/questions/14907518/modal-view-controllers-how-to-display-and-dismiss – Rog Jul 15 '14 at 15:14
  • I would have expected to be able to generate a UIAlertView from anywhere and would expect the default 'cancel' button to close that alert without me having to do anything for it to do so 'cleanly'. I have even tried creating the alert from within the main view controller but closing the alert gives the same warning in this case. I'm starting to suspect it is a bug. – Pinxaton Jul 15 '14 at 18:04
  • 1
    I'm having the same problem. Not using spritekit or Swift (100% objective-c). Tapping cancel causes the error, and makes the next actionsheet to load extremely slowly. – element119 Jul 16 '14 at 17:13
  • 1
    Also, I've been trying to debug this and I noticed that didPresentActionSheet is NOT being called. This is consistent with it "not being displayed" technically. – element119 Jul 16 '14 at 18:54

1 Answers1

5

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.

JOM
  • 8,139
  • 6
  • 78
  • 111
dianna
  • 156
  • 1
  • 1
  • 5