How do you get the time interval for UIDatePicker in UIDatePickerModeCountDownTimer mode?
I have a UIViewController
with a UIDatePicker
datePicker property. I have configured it in Interface Builder to have a UIDatePicker
in "Timer" mode and to have it call the datePickerValueDidChange:
method of the view c开发者_运维问答ontroller when the "Value Changed" event occurs. The code in the view controller looks like this:
- (void) viewWillAppear:(BOOL)animated {
NSLog(@"datePicker: %@", datePicker);
NSLog(@"datePicker.datePickerMode: %d", datePicker.datePickerMode);
}
And when the view loads, you see this in the log
datePicker: <UIDatePicker: 0x3b03660; frame = (0 61; 320 216); clipsToBounds = YES; opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x3b033a0>>
datePicker.datePickerMode: 3
So that means the date picker is initialized and the mode is UIDatePickerModeCountDownTimer
. When I change the value by moving one of the scroll wheels, it calls this method:
- (IBAction) datePickerValueDidChange:(id)sender {
NSLog(@"datePicker.countDownDuration: %@", datePicker.countDownDuration);
}
And the output in the log is:
datePicker.countDownDuration: (null)
Why is it null? Is this not the way to get the value for the hours/minutes the user has selected? If not, how can you get those values?
countDownDuration is an NSTimeInterval (really a double). To print it out, you'll need to use
NSLog(@"datePicker.countDownDuration: %f", datePicker.countDownDuration);
精彩评论