I'm trying to get a datepicker in countdowntimer mode to simply allow me to select minutes and seconds and then get that value when you click a button. I set up the picker in IB and use this code, but the result is always Null when I select any combination of minutes and hours and click the button...Obviously I'm missing something. Any help on getting this to work would be appreciated.
@interface ThisPicker : UIViewController {
IBOutlet UIDatePicker *datePicker;
}
-(IBAction)buttonPressed:(id)sender;
@end
@implementation ThisPicker
-(IBAction)buttonPressed:(id)sender{
datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = UIDatePickerModeCountDownTimer;
NSLog(@"%@",[datePicker countDownDuration]);
}
@end
If you want in a Hour Minute format
-(IBAction)buttonPressed:(id)sender
{
NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"HH:mm:ss"];
NSLog(@"%@",[dateformatter stringFromDate:[datePicker date]]);
}
I believe that countDownDuration
is a double.
Try accessing it this way:
NSLog(@"%f", datePicker.countDownDuration);
Edit: What you need to do is link your date picker in IB with the one in code and don't alloc it as it's causing an erase of your data.
Edit2: BuildSucceeded
beat me to it. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With