If you have references to each picker view, then you'd just do something like this
// These are instance variables within the view controller
NSString *selectedCountry;
NSArray *listOfCountries = @[@"France", @"Switzerland"];
// In the picker view delegate callback
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (pickerView == countryPickerView) {
selectedCountry = [listOfCountries objectAtIndex:row];
[cityPickerView reloadAllComponents]; // Or you can reload individual components
}
}
The cityPickerView
's datasource should be looking for what the value of selectedCountry
is and populating itself with cities for that given country.
As a side note, if you have multiple picker views within a single view, you may want to consider creating a subclass for each UIPickerView and making the subclass the delegate/datasource for each pickerview so you don't end up with spaghetti code and having to check if (pickerView == countryPickerView)
like in this example.