I\'ve run into a weird effect that sure looks like a bug in iOS7 -- but often in the past, when I have thought I found a bug in Apple\'s APIs, it has turned out to be my own
If someone still having problems with datepicker... I'm using Swift / iOS 8 / Xcode 6.3
To solve the problem you should not use picker.countDownDuration = NSTimeInterval
. Use .setDate(NSDate, animated: true)
.
it works direct on viewDidLoad()
, don't need to use queues
The complete snippet:
override func viewDidLoad() {
super.viewDidLoad()
picker.setDate(setDateFromSeconds(seconds), animated: true)
}
func setDateFromSeconds(seconds: Double) -> (NSDate) {
let intSeconds = Int(seconds)
let minutes = (intSeconds / 60) % 60
let hours = intSeconds / 3600
let dateString = NSString(format: "%0.2d:%0.2d", hours, minutes)
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "hh:mm"
return dateFormatter.dateFromString(dateString as String) as NSDate!
}