有时在致电UIAlert
尝试加载视图控制器的视图 不允许取消分配,可能导致未定义的行为 ()
code used:
func alert (dictKey: String){
print(dictKey)
let alertController = UIAlertController(title: nil, message: promptsArr[dictKey], preferredStyle: .Alert )
let OKAction = UIAlertAction(title: "OK", style: .Default) { (action) in
}
alertController.addAction(OKAction)
if self.presentedViewController == nil {
delay(1.0){
self.presentViewController(alertController, animated: true, completion: nil)
}
} else {
self.presentedViewController!
}
答案 0 :(得分:2)
删除delay()
将逻辑放在self.presentedViewController
中:
(如果存在,则无需创建警报)
func alert (dictKey: String){
if self.presentedViewController == nil {
let alertController = UIAlertController(
title: nil,
message: promptsArr[dictKey],
preferredStyle: .Alert )
let OKAction = UIAlertAction(title: "OK", style: .Default) {
(action) in
}
alertController.addAction(OKAction)
self.presentViewController(
alertController,
animated: true,
completion: nil)
}
}