UIDatePicker in UIDatePickerModeCountDownTimer mode: how to get/set the hours and minutes via code?
How to get/set the hours and minutes via code from a UIDatePicker in UIDatePickerModeCountDownTimer mode?
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.
Solutions Collect From Internet About “UIDatePicker in UIDatePickerModeCountDownTimer mode: how to get/set the hours and minutes via code?”
You have to use the
countDownDuration property in
UIDatePicker when the date picker mode is set to
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 any
// Create a new date with the current time NSDate *date = [NSDate new]; // Split up the date components NSDateComponents *time = [[NSCalendar currentCalendar] components:NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:date]; NSInteger seconds = ([time hour] * 60 * 60) + ([time minute] * 60); UIDatePicker *picker = [UIDatePicker new]; [picker setDatePickerMode:UIDatePickerModeCountDownTimer]; [picker setCountDownDuration:seconds]; [[self view] addSubview:picker];
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 🙂
- UIButton in Swift is not registering touches
- Swift Playground and Simulator Error (ipc/mig) server died, Unable to boot the iOS Simulator
- linking and using a C++ library with an Objective-C application
- Get arguments of objective-c method by index
- Should the rfc1034identifier be removed from the CFBundleIdentifier in plist file?
- Xcode Image Asset By Device
- How to save image to custom album?
- How to combine video clips with different orientation using AVFoundation
- iOS app review process: app requires external hardware (connecting over WiFi)
- set Dynamic width and height of collection view cell
- FBSDKLoginManager logInWithPublishPermissions always returns isCancelled=YES
- iOS – UITableView delegate not being set?
- ld: library not found for -lz
- MKMapView MKPointAnnotation tap event
- How can I customize the selection state of my UICollectionViewCell subclass?