Not directly -- the UIPickerView can only have one data source at a time. However, you can switch data source when the user changes the segment. Note that you need to change the delegate of the picker view too, since it is the delegate that supplies the actual content of the picker.
Here is an example where you have two objects that implement UIPickerViewDataSource and UIPickerViewDelegate. The method is invoked when the user clicks on either of the segments in the control:
- (void)segmentedControlValueChanged {
switch (segmentedControl.selectedSegmentIndex) {
case 0:
pickerView.delegate = personDelegate;
pickerView.dataSource = personDelegate;
break;
case 1:
pickerView.delegate = placeDelegate;
pickerView.dataSource = placeDelegate;
break;
default:
break;
}
[pickerView reloadComponent:0];
}
But honestly, I think a better solution is to just have your pickerView:titleForRow:forComponent look at the segmented control.
Assuming you have two NSArrays called persons and places:
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *result;
switch (segmentedControl.selectedSegmentIndex) {
case 0:
result = [self.persons objectAtIndex:row];
break;
case 1:
result = [self.places objectAtIndex:row];
break;
default:
result = @"Error!";
break;
}
return result;
}
- (void)segmentedControlValueChanged {
[pickerView reloadComponent:0];
}