i countdown 3 seconds in alert controller. not sure how this. can alert disappear in 3 seconds, countdown missing.
//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) }
after set delay time dismiss view controller, can set timer call function after second like:
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") }
and update title new time.
Comments
Post a Comment