选择器查看一个组件隐藏和其他组件取消隐藏

时间:2016-04-27 12:35:53

标签: ios objective-c uipickerview

我厌倦了选择器视图中的两个组件,即(货币),(id)并显示但我的问题是如何隐藏" id"选择器视图中的组件。"货币"在responseArray和" id"在responseArray1。

选择器视图委托:

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;{
    return 2;

}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;{
        return [responseArray count];
    }

-(NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;{
    //return [responseArray objectAtIndex:row];
    if (component == 0) {
        return [responseArray objectAtIndex:row];
    } else {
        return [responseArray1 objectAtIndex:row];


    }
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
{

    NSLog([responseArray1 objectAtIndex:row]);
    if (component == 0) {
        [pickerView selectRow:row inComponent:1 animated:YES ];
    } else if(component == 1)
    {
        if (row != [pickerView selectedRowInComponent:0])
        {
            [pickerView selectRow:[pickerView selectedRowInComponent:0] inComponent:1 animated:YES];
        }

    }
}

1 个答案:

答案 0 :(得分:0)

根据评论回答:

 -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;{
return 1;

}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return [responseArray count];
}

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


return [responseArray objectAtIndex:row];



}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{

NSLog(@"rsponse currency : %@",[responseArray objectAtIndex:row]);
NSLog([responseArray1 objectAtIndex:row]);



// You can fetch value from both array using row parameter.
// You can display currency and id for particular row from here like above

}

您不需要在pickerview中显示两个组件。只需显示一个您想要显示的内容,根据所选行,您可以从数组中获取相应的元素。

希望这会有所帮助:)