Reputation: 64
Is there any way to disable a particular date in uidatepicker ?
Upvotes: 0
Views: 2302
Reputation: 1010
Since there is not direct method to implement this, what you can do is get the "UIControlEventValueChanged" from datePicker like
UIDatePicker * datePick = [[UIDatePicker alloc] init];
[datePick addTarget:self action:@selector(disableDate) forControlEvents:UIControlEventValueChanged];
In disableDate method, the user can check if the current date is equal to the disableDate.If yes, then he can set the currentDate to some previous date.
-(void)disableDate{
NSDate *pickedDate = datePicker.date; // Get current Date
NSDate *disabledDate = [self getDisabledDate] // Returns Disabled Date.(getDisabledDate returns a date to be diabled).
if([pickedDate compare:disabledDate] == NSOrderedSame){
[datePick setDate:[self someOtherDate] animated:YES];
// Set current Date to some other date(someOtherDate methos returns a date to be set ,if disabled date is selected). }
Upvotes: 2