2017-12-02 86 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)