ios - UIAlertView 显示警报显示晚于需要 ios

标签 ios swift uialertview

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

在接下来的时间里,“visited full”在第一次点击时打印出来,但在第二次点击时出现警告,为什么会出现这种情况?请帮我解决。提前致谢

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

最佳答案

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

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)
})

关于ios - UIAlertView 显示警报显示晚于需要 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26883804/

相关文章:

iphone - 使用 JSON 查询模拟 MVC 架构

ios - 如何设置加载 uicollectionview 时选择的项目?

ios - NSURLSession/NSURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9801)

swift - 创建自定义类并从 Storyboard添加到我的 View Controller ?

objective-c - 是否可以在 UIAlertView 中显示图像?

objective-c - HTTP Post 连接保证

ios - 运行应用程序时字体发生变化

swift - RealmSwift 和 watchos2

ios - 在 iOS 7 的横向模式下将 UIAlertView 稍微向下移动

ios - 链接 UIAlertAction 打开另一个 ViewController