Daemon
Daemon

Reputation: 439

minimumDate and maximumDate of UIDatePicker cannot be set in code?

In my NIB file, I have a UIDatePicker. I connect it to a IBOutlet property. In the - (id) initWithCoder:(NSCoder *)aDecoder method in my Controller, I set the minimumDate and maximumDate like this:

- (id) initWithCoder:(NSCoder *)aDecoder {
    if (self = [super initWithCoder:aDecoder]) {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];  
        [dateFormatter setDateFormat:@"yyyy-MM-dd"]; 
        NSDate *beginDate = [dateFormatter dateFromString:@"2010-01-01"];  
        NSDate *endDate = [dateFormatter dateFromString:@"2010-12-31"]; 
        picker.minimumDate = beginDate;
        picker.maximumDate = endDate;
    }
    return self;
}

But when the app is running, there is no change about my UIDatePicker. Did I have some mistakes?

Thanks!

Upvotes: 0

Views: 375

Answers (1)

Macmade
Macmade

Reputation: 53930

Your picker binding is not done in the initWithCoder method, as the XIB file is not loaded at this stage.

Place you code in awakeFromNib

- ( void )awakeFromNib
{
   ...
}

And by the way, you forgot to release your NSDateFormatter object...

Upvotes: 3

Related Questions