Reputation: 671
I have an array of dates ,is it possible to assign those dates as datasourse of the UIDatePicker in an iphone app ? if so, how can i do that? Thanx in advance!
Upvotes: 0
Views: 208
Reputation: 259
use normal UIPickerView, instead of UIDatePickerView. You can create sections in UIPickerView You will have to implement the datasource and the delegate.
once you press a button, set an array pointer to the appropriate array.
than call [thePicker reloadAllComponents];
-(IBAction) usButtonPressed:(id)sender{
self.inputArray = self.usArray;
[self.thePicker reloadAllComponents];
}
-(IBAction) mexicoButtonPressed:(id)sender{
self.inputArray = self.mexicoArray;
[self.thePicker reloadAllComponents];
}
the datasource methods:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [self.inputArray count];
}
the delegate methods:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [self.inputArray objectAtIndex:row];
}
Upvotes: 0
Reputation: 1632
You could try something like this:
NSString * str = [[NSString alloc]initWithFormat:@"%@",[yourDateArray objectAtIndex:0]];
yourDatePicker.date = [[NSDateFormatter alloc] init] dateFromString:str];
Hope this helps.
Upvotes: 1
Reputation: 20021
UIDatePicker does not have a data source.Use UIPickerView
for the purpose ,load your dates and Bang.good to go
Upvotes: 1
Reputation: 4705
No you cant use a UIDatePicker like that. You can make use of UIPickerView.
Upvotes: 0