実際には非常に簡単です。component 1
で選択されているものに応じて、関連する色を返す必要がありますcomponent 0
。例:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
//...
case 1:
{
NSArray *colors = [self colorsWithSelection:self.selectedRow0];
return colors[row];
}
//...
}
次に、以下を実装します。
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (component == 0)
{
self.selectedRow0 = row;
[pickerView reloadComponent:1];
dispatch_async(dispatch_get_main_queue(), ^{
[pickerView selectRow:0 inComponent:1 animated:YES];
});
}
}
明らかにこれは最適化できますが、それはアイデアを示しています。