[英]UIDatePicker setMinimumDate and setMaximumDate sets null
I have no idea why this extremely basic piece of code sets null values. 我不知道为什么这段极其基本的代码会设置空值。
NSDate *currentTime = [NSDate date];
[datePicker setMinimumDate:currentTime];
[datePicker setMaximumDate:[currentTime dateByAddingTimeInterval:kSecondsInYear]];
NSLog(@"cur: %@, min: %@, max: %@",currentTime,datePicker.minimumDate,datePicker.maximumDate);
Output: cur: 2011-09-09 16:18:18 GMT, min: (null), max: (null) 输出:cur:2011-09-09 16:18:18 GMT,最小值:(null),最大值:(null)
Given that the following works fine, the issue is definitely with datePicker. 鉴于以下工作正常,绝对是datePicker的问题。
UIDatePicker* datePicker = [[UIDatePicker alloc] init];
NSLog(@"DatePicker: %@", datePicker);
NSDate *currentTime = [NSDate date];
[datePicker setMinimumDate:currentTime];
[datePicker setMaximumDate:[currentTime dateByAddingTimeInterval:40000]];
NSLog(@"cur: %@, min: %@, max: %@",currentTime,datePicker.minimumDate,datePicker.maximumDate);
If you add NSLog(@"DatePicker: %@", datePicker);
如果添加NSLog(@"DatePicker: %@", datePicker);
to your code snippet it should report something a bit like: DatePicker: <UIDatePicker: 0x4b36740; frame = (0 0; 320 216); layer = <CALayer: 0x4b33940>>
在您的代码段中,它应该报告如下内容: DatePicker: <UIDatePicker: 0x4b36740; frame = (0 0; 320 216); layer = <CALayer: 0x4b33940>>
DatePicker: <UIDatePicker: 0x4b36740; frame = (0 0; 320 216); layer = <CALayer: 0x4b33940>>
DatePicker: <UIDatePicker: 0x4b36740; frame = (0 0; 320 216); layer = <CALayer: 0x4b33940>>
. DatePicker: <UIDatePicker: 0x4b36740; frame = (0 0; 320 216); layer = <CALayer: 0x4b33940>>
。 If it returns (null)
(which I very strongly suspect) then it's either not created programmatically or it's not hooked up in Interface Builder. 如果它返回(null)
(我非常怀疑),那么它要么不是以编程方式创建的,要么没有连接到Interface Builder中。
Found the problem, I was setting the min/max date in the initwithnib method. 发现了问题,我在initwithnib方法中设置了最小/最大日期。 When I changed it to the viewDidLoad method it worked fine. 当我将其更改为viewDidLoad方法时,它可以正常工作。 whoops. 哎呦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.