UIDatePicker setMinimumDate 和 setMaximumDate 设置为 null

发布于 2024-12-03 22:56:53 字数 364 浏览 0 评论 0原文

我不知道为什么这段极其基本的代码设置空值。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九歌凝 2024-12-10 22:56:53

鉴于以下工作正常,问题肯定出在 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);

如果您将 NSLog(@"DatePicker: %@", datePicker); 添加到代码片段中,它应该报告类似于: DatePicker:>。如果它返回 (null) (我非常怀疑),那么它要么不是以编程方式创建的,要么没有连接到 Interface Builder 中。

Given that the following works fine, the issue is definitely with 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); 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.

椒妓 2024-12-10 22:56:53

发现问题,我在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文