【问题标题】:Countdown in UIAlertControllerUIAlertController 中的倒计时
【发布时间】:2016-04-06 12:18:18
【问题描述】:

我想在我的警报控制器中倒计时 3 秒。不知道该怎么做。我可以让警报在 3 秒内消失,只是倒计时不见了。

//simple alert dialog
let alertController = UIAlertController(title: "Workflow successful", message: "Modified reminder's priority or list.", preferredStyle: .Alert)

var secs = 3
let defaultAction = UIAlertAction(title: "Dismiss in " + secs, style: .Default, handler: nil)
alertController.addAction(defaultAction)

dispatch_async(dispatch_get_main_queue()) {
    //self.presentViewController(alertController, animated: true, completion: nil)
    self.showViewController(alertController, sender: self)
}

let delayTime = dispatch_time(DISPATCH_TIME_NOW,
              Int64(secs * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
    alertController.dismissViewControllerAnimated(true, completion: nil)
}

【问题讨论】:

    标签: swift delay uialertcontroller


    【解决方案1】:

    设置延迟时间以关闭视图控制器后,您可以设置一个计时器以在一秒钟后调用函数,例如:

    var timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(self.decrease), userInfo: nil, repeats: true)
    
    func decrease()
    {
        self.secs-=1
        self.defaultAction.setValue("Dismiss in \(self.secs)", forKey: "title")
    }
    

    它会用你的新时间更新标题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多