UIDatePicker setMinimumDate 和 setMaximumDate 设置为 null
我不知道为什么这段极其基本的代码设置空值。
NSDate *currentTime = [NSDate date];
[datePicker setMinimumDate:currentTime];
[datePicker setMaximumDate:[currentTime dateByAddingTimeInterval:kSecondsInYear]];
NSLog(@"cur: %@, min: %@, max: %@",currentTime,datePicker.minimumDate,datePicker.maximumDate);
输出:当前:2011-09-09 16:18:18 GMT,最小值:(空),最大值:(空)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
鉴于以下工作正常,问题肯定出在 datePicker 上。
如果您将
NSLog(@"DatePicker: %@", datePicker);
添加到代码片段中,它应该报告类似于:DatePicker:>
。如果它返回(null)
(我非常怀疑),那么它要么不是以编程方式创建的,要么没有连接到 Interface Builder 中。Given that the following works fine, the issue is definitely with datePicker.
If you add
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>>
. 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.发现问题,我在 initwithnib 方法中设置最小/最大日期。当我将其更改为 viewDidLoad 方法时,它工作正常。哎呀。
Found the problem, I was setting the min/max date in the initwithnib method. When I changed it to the viewDidLoad method it worked fine. whoops.