I have a UIDatePicker
mm/dd/yy. It works fine, but there is one problem: I set minimum
and maximum
date to it, and when user tries to choose the forbidden day, month or year, the [datePicker date]
property begins working wrong. It returns you the current day - 1
or current month - 1
or current year - 1
. I added some pictures, so you can see the situation.
This is correct
This is wrong (After choosing the forbidden date)
Does somebody know, how can I fix this ? Thanks !
UPD: Code
[self.myDatePicker setMinimumDate:[NSDate date]];
[self.myDatePicker setMaximumDate:[[NSDate date] addTimeInterval:2 * 365.25 * 24 * 60 * 60]]; // to get upto 5 years
NSDate * now = [[NSDate alloc] init];
[self.myDatePicker setDate: now animated: YES];
self.myDatePicker.timeZone = [NSTimeZone localTimeZone];
self.myDatePicker.calendar = [NSCalendar currentCalendar];
addTimeInterval:
isnt classic. you shouldnt do date calculation like that. please watch WWDC 2011 Video "Session 117 - Performing Calendar Calculations" – Marshallmarshallese