Date picker scrolls to past date, even though minimum date is set to current date

Ankit Jain picture Ankit Jain · Mar 20, 2013 · Viewed 9.1k times · Source

Strange behavior in iOS 6.1 I have set the minimum date to current date for my date picker like this

NSDate *currentTime = [NSDate date];
[picker setMinimumDate:currentTime];

enter image description here

But when I run the app I am able to scroll to past date, though its not selected, picker doesn't jump back to current date. It's happening only with iOS 6.1 version and in rest picker is behaving normally.

Answer

Adrien G picture Adrien G · May 6, 2013

I got the same issue as you and fixed it with only setting the date to the maximum date manually (in this case I set the limit to the current date):

- (IBAction)pickerValueChanged:(id)sender {

    dispatch_async(dispatch_get_main_queue(), ^{
        UIDatePicker *datePicker = (UIDatePicker *)sender;

        if ([self.datePicker.date compare:[NSDate date]] == NSOrderedDescending) {

            datePicker.date = [NSDate date];
        }

    });
}

This function is triggered when the date value from the date picker did change. you can set a maximum or minimum value here.