It depends on how you are going to store the data. For example, if you have an array as the value of a dictionary key, and this dictionary has different such keys, the first column will be the keys, and when you select it, you will display the array in another column (component). - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView method should return 2. - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component method, you need to specify the number of keys in the dictionary for component 1 and the number of selected array the current key. eg,
if(component==0) return [[DICTIONARY allKeys] count]; else return [[DICTIONARY objectForKey:@"SELECTED_KEY"] count];
Then
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { selectedIndex = [pickerView selectedRowInComponent:0]; if (component == 1 && !(selectedIndex < 0)) { [pickerView reloadComponent:2]; [pickerView selectRow:0 inComponent:2 animated:YES]; } }
and
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { UILabel *pickerRow = (view != nil) ? view : [[[UILabel alloc] initWithFrame:CGRectMake(5, 0, 115, 60)] autorelease]; pickerRow.font = [UIFont boldSystemFontOfSize:14]; pickerRow.textAlignment = UITextAlignmentLeft; pickerRow.backgroundColor = [UIColor clearColor]; pickerRow.textColor = [UIColor blackColor]; pickerRow.numberOfLines = 0; if (component == 0) { pickerRow.text = @"DICTIONARY_ROW'th_KEY"; } else { pickerRow.text = [[dictionary objectForKey:@"SELECTED_KEY"] objectAtIndex:row]; } return pickerRow; }
source share