我有一个看起来像这样的DatePicker:
我从DatePicker中选择日期设置通知,显然我不需要过去的日期,我该如何隐藏它们?我尝试了一些我在其他问题中发现但没有工作的东西,看起来像这样:
[super viewDidLoad];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *currentDate = [NSDate date];
NSDateComponents *comps = [[NSDateComponents alloc] init];
NSDate *minDate = [calendar dateByAddingComponents:comps toDate:currentDate options:0];
[self.DatePicker setMinimumDate:minDate];
谢谢!
答案 0 :(得分:2)
试试这个
[picker setMinimumDate: [NSDate date]];
或尝试此代码
NSCalendar *calendar = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDate *currentDate = [NSDate date];
NSDateComponents *comps = [[[NSDateComponents alloc] init] autorelease];
[comps setYear:30];
NSDate *maxDate = [calendar dateByAddingComponents:comps toDate:currentDate options:0];
[comps setYear:-30];
NSDate *minDate = [calendar dateByAddingComponents:comps toDate:currentDate options:0];
[datePicker setMaximumDate:maxDate];
[datePicker setMinimumDate:minDate];
它有希望对你有用。