11

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

我还应该补充一点,当警报出现时,当我选择 Debug -> View Debugging -> Capture View Hierarchy 时,警报不会显示在视图的 3d 视图中。我想知道这是否是我做错了什么的症状。

4

1 回答 1

5

我得到了同样的警告:

警告:尝试从视图控制器 <_UIAlertShimPresentingViewController:> 中关闭,同时进行演示或关闭!

在 iOS8 中,UIAlertController 取代了 UIAlertView。这应该解决您的警告(在 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];

有关更多信息,请参阅UIAlertController 的文档。

于 2014-07-31T00:54:23.540 回答