在UIDatePickerModeCountDownTimer模式下,如何获取UIDatePicker的时间间隔? [英] How do you get the time interval for UIDatePicker in UIDatePickerModeCountDownTimer mode?
问题描述
我有一个带有UIDatePicker
datePicker属性的UIViewController
.我已经在Interface Builder中将其配置为在计时器"模式下具有UIDatePicker
,并在发生值更改"事件时让其调用视图控制器的datePickerValueDidChange:
方法.视图控制器中的代码如下所示:
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 controller 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
因此这意味着日期选择器已初始化且模式为UIDatePickerModeCountDownTimer
.当我通过移动一个滚轮来更改值时,它将调用此方法:
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);
}
日志中的输出为:
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是一个NSTimeInterval(实际上是一个double).要打印出来,您需要使用
countDownDuration is an NSTimeInterval (really a double). To print it out, you'll need to use
NSLog(@"datePicker.countDownDuration: %f", datePicker.countDownDuration);
这篇关于在UIDatePickerModeCountDownTimer模式下,如何获取UIDatePicker的时间间隔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!