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开发者_C百科 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!
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...
精彩评论