How to get/set the hours and minutes via code from a UIDatePicker in UIDatePickerModeCountDownTimer mode?
The situation:
I have an interface in that a user selects just hours and minutes. Then, he saves the information (so, I have to get the hours and minutes from UIDatePicker via code to save in a DB).
When the user is editing the information saved previously, I want to start the interface with the saved hours/minutes (so, I have to set the UIDatePicker hours and minutes via code with values from DB).
How do I do that with the UIDatePicker in UIDatePickerModeCountDownTimer mode?
Thanks in advance.
You have to use the
countDownDuration
property inUIDatePicker
when the date picker mode is set toUIDatePickerModeCountDownTimer
.The countdown duration is in seconds, so you can calculate that from a NSDate as follows (to test it just drop it into the
viewDidLoad
of anyUIViewController
):So if the current time is 17:28, the
UIDatePicker
will show "17 hours 28 mins". Simly replace the NSDate with the one you get from the DB and you should be sorted :)