[英]Disabling a particular date in uidatepicker in objective c
有没有办法在uidatepicker中禁用特定日期?
由于没有直接的方法来实现它,你可以做的是从datePicker得到“UIControlEventValueChanged”
UIDatePicker * datePick = [[UIDatePicker alloc] init];
[datePick addTarget:self action:@selector(disableDate) forControlEvents:UIControlEventValueChanged];
在disableDate方法中,用户可以检查当前日期是否等于disableDate。如果是,则可以将currentDate设置为某个先前的日期。
-(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];
//将当前日期设置为其他日期(如果选择了禁用日期,someOtherDate方法将返回要设置的日期)。 }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.