Possible Duplicate:
UIDatePicker set Maximum date
I am using this code to block the user from going over the limit I set:
in view did load:
NSDate *Date=[NSDate date];
[DatePickerForDate setMinimumDate:Date];
[DatePickerForDate setMaximumDate:[Date dateByAddingTimeInterval: 63072000]]; //time interval in seconds
And this method:
- (IBAction)datePickerChanged:(id)sender{
// When `setDate:` is called, if the passed date argument exactly matches the Picker's date property's value, the Picker will do nothing. So, offset the passed date argument by one second, ensuring the Picker scrolls every time.
NSDate* oneSecondAfterPickersDate = [DatePickerForDate.date dateByAddingTimeInterval:1] ;
if ( [DatePickerForDate.date compare:DatePickerForDate.minimumDate] == NSOrderedSame ) {
NSLog(@"date is at or below the minimum") ;
DatePickerForDate.date = oneSecondAfterPickersDate ;
}
else if ( [DatePickerForDate.date compare:DatePickerForDate.maximumDate] == NSOrderedSame ) {
NSLog(@"date is at or above the maximum") ;
DatePickerForDate.date = oneSecondAfterPickersDate ;
}
}
The code in the if statements is never called. Why?
Don’t you want to finish our discussion over here?
First, make sure the
datePickerChangedis being called when DatePickerForDate’s value is changed.