我正在通过以下方式创建警报:
let alert = UIAlertView(title: "Network Unavailable",
message: "Oh noes!",
delegate: nil,
cancelButtonTitle: "OK")
alert.show()
工作正常。但是,当我单击“确定”按钮关闭警报时,我得到以下信息:
警告:在演示或关闭过程中尝试从 View Controller <_UIAlertShimPresentingViewController: 0x16ea2230> 关闭!
一些上下文:
任何想法为什么会发生此警告?我不想忽略它,以防它在 future 版本的 iOS 中变成 fatal error 。
更新
我还应该补充一点,当警报出现时,当我选择 Debug -> View Debugging -> Capture View Hierarchy 时,警报不会显示在 View 的 3d View 中。我想知道这是否是我做错了什么的症状。
最佳答案
我得到了同样的警告:
警告:尝试从 View Controller <_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];
见documentation for UIAlertController了解更多信息。
关于warnings - 关闭时的 UIAlertView 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24747640/