UIAlertView显示的警报显示比所需的时间晚

时间:2014-11-12 09:47:46

标签: ios swift uialertview

我正在使用UIAlertView显示警报,并且它第一次工作时,当我点击警报时出现但第二次我这样做时,然后点击两次警报显示而不是第一次点击。

在很长一段时间内,“访问完整”会在第一次点击时打印出来,但在2点击时出现警告,为什么会出现?请帮我解决。谢谢提前

println("visited full")
var alert:UIAlertView = UIAlertView(title: "Video", message: "You have played all videos", delegate: self, cancelButtonTitle: "OK")
  alert!.show()

1 个答案:

答案 0 :(得分:12)

如果它不起作用,那么试试这可能会有效。

let alert = UIAlertController(title: "Video", message: "You have played all videos", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)

修改: 我想你也可以这样使用它:

dispatch_async(dispatch_get_main_queue(), {
    var alert:UIAlertView = UIAlertView(title: "Video", message: "You have played all videos", delegate: self, cancelButtonTitle: "OK")
    alert.show()
})

UIAlertController

dispatch_async(dispatch_get_main_queue(), {
    let alert = UIAlertController(title: "Video", message: "You have played all videos", preferredStyle: UIAlertControllerStyle.Alert)
    alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
    self.presentViewController(alert, animated: true, completion: nil)
})