2017-12-02 78 views
0

我使用的是UIDatePickerCount Down Timer模式供用户输入出行时间: enter image description here的setdate在倒计时器模式下的UIDatePicker

,我可以返回的时间以秒这样的:

@IBAction func customTimeSelected(_ sender: Any) { 
    print("user selected custom time: \(customeTimePicker.countDownDuration)") 
} 

但是如何以秒为单位设置UIDatePicker

继承人我尝试:

let travelDate = Date(timeIntervalSinceNow: TimeInterval(5400)) // hour and a half in seconds 
self.customeTimePicker.setDate(travelDate, animated: false) 

然而,这会返回一个不正确的时间:

enter image description here

回答

0

刚刚发现的正确方法是计时器而不是setDate使用countDownDuration。无需Dates或者,只是一个TimeInterval

self.customeTimePicker.countDownDuration = TimeInterval(5400)