开发者

UIDatePicker setMinimumDate and setMaximumDate sets null

开发者 https://www.devze.com 2023-04-04 00:22 出处:网络
I have no idea why this extremely basic piece of code sets null values. NSDate *currentTime = [NSDate date];

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)


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消