swift - 我应该如何发出 swift 超时的警报

标签 swift uialertcontroller

我正在使用 UIAlertController 来显示需要用户操作的用户警报。我想跳过用户操作并在一段时间后(比如 10 秒)让警报消失。这样做的最佳方法是什么?

最佳答案

在创建 UIAlertViewController 后试试这个

var dispatchTime: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(10.0 * Double(NSEC_PER_SEC))) 
dispatch_after(dispatchTime, dispatch_get_main_queue(), { 
    yourAlertViewController.dismissViewControllerAnimated(true, completion: nil)   
})

关于swift - 我应该如何发出 swift 超时的警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30301549/

相关文章:

ios - UISegmentedControl if 语句

ios - 如何检查对象是否具有存储属性?

swift - 如何在类中包含初始值设定项但仍然能够访问类的值

ios - AlertController - 与 UIViewController 冲突

ios - 如何锁定 UIAlertController 方向?

ios - '调用中的额外参数 'id'' 与 Swift 结构

ios - 如何为我的 iOS 应用程序集成维护模式

iOS:大型 UIAlertController ActionSheet 在滚动时弹跳并且不显示行分隔符

ios - 警报不会解除(警告 : Attempt to dismiss from view controller. ..)

swift - 在 SFSafariViewController 中打开从二维码扫描的 URL