I am making an iphone app on one of the view I am using a date picker. I have an another date which I am fetching from the database. Now I want that the date picker enable from the selected date so that user couldn't get unable to select the same date again. Is there any way to enable the picker from selected date. If anyone know please help me.
-(void)findextenddate
{
NSLog(@"count:%@",adddatetime);
addatimeclass = adddatetime;
endnsdate = [addatimeclass objectAtIndex:[addatimeclass count]-1];
endnsdate1 = (NSDate*) endnsdate;
NSLog(@"formatdate:%@",endnsdate1);
}
-(IBAction)clicktoextend:(id)sender
{
actionsheet = [[UIActionSheet alloc]init];
actionsheet = [[UIActionSheet alloc] initWithTitle:@"Select Date" delegate:self
cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Select", nil];
[actionsheet showInView:[self.view superview]];
[actionsheet setFrame:CGRectMake(0, 117, 320, 383)];
pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 320, 216)];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter开发者_如何学C setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
pickerView.minimumDate = endnsdate1 ;
pickerView.datePickerMode = UIDatePickerModeDate;
//Add picker to action sheet
[actionsheet addSubview:pickerView];
subviews = [actionsheet subviews];
[[subviews objectAtIndex:SelectButtonIndex] setFrame:CGRectMake(20, 266, 280, 46)];
[[subviews objectAtIndex:CancelButtonIndex] setFrame:CGRectMake(20, 317, 280, 46)];
[pickerView release];
[actionsheet release];
}
Thanks alot.
Yes, UIDatePicker has minimumDate
property which serves exactly that purpose
USE
datePicker.minimumDate=YOUR date object
this function disable all dates before your date
If you meant that you need to set the date of the picker to the one you are fetching from the database, you can do so via the - (void)setDate:(NSDate *)date animated:(BOOL)animated
method.
If you need to enable the picker from that date ONWARDS (no past dates), set the minimumDate
property as is suggested by the earlier answers.
精彩评论