在我的视图控制器中的两个选择器视图之间进行通信

时间:2013-12-30 07:46:06

标签: ios iphone objective-c uipickerview

在我的项目中,picker1中有两个类别(音频/电视)。当用户点击音频行时,picker2中的以下列表应更改为( audio1,audio2,audio3 ),如果在picker1中选择了tv,则在picker2中更改为( tv1,tv2, TV3 )。

我应该在以下功能中写什么?

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    if ([[devicecatogery objectAtIndex:row] isEqual:@"Audio"]) {
        NSLog(@"Audio is selected");
     }else if ([[devicecatogery objectAtIndex:row] isEqual:@"TV"]){
       NSLog(@"TV is selected");
    }    
    NSLog(@"selected row:%d , component:%d" , row,component);
    }
}

2 个答案:

答案 0 :(得分:0)

当您更改选择器1时,您可以使用[picker2 selectRow:3 inComponent:0 animated:NO];更改选择器2,并设置您想要的值。

答案 1 :(得分:0)

您必须更改第二个选择器值数组。这是您在以下方法中使用的数组:

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component

更改值数组后,必须以这种方式重新加载第二个选择器组件:

[secondPicker reloadAllComponents] /*or [secondPicker reloadComponent:0] if you have only one component*/
相关问题