pir800
pir800

Reputation: 1011

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)

Upvotes: 2

Views: 4127

Answers (2)

pir800
pir800

Reputation: 1011

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.

Upvotes: 2

Obliquely
Obliquely

Reputation: 7072

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.

Upvotes: 5

Related Questions