我使用UIAlertController
来显示需要用户操作的用户提醒。我想跳过用户操作并在一段时间后(例如10秒)使警报消失。这样做的最佳方法是什么?
答案 0 :(得分:2)
创建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)
})
答案 1 :(得分:1)
这对你来说非常合适
//Define & Initialize Alert (Example)
var alert: UIAlertController = UIAlertController();
// Delay the execution (Dismiss AlertController) by 10 seconds
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
alert.dismissViewControllerAnimated(true, completion: nil)
});