如何在UIPickerView上获取文本?

时间:2011-01-13 03:44:22

标签: iphone objective-c uipickerview

如果我使用带有自定义View的UIPickerView(3个组件)。如何从每个selectedRow获取UIPickerView上的每个文本?

感谢...

2 个答案:

答案 0 :(得分:0)

这取决于您决定如何将文本放入组件中。

例如,如果您使用myArray

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    NSLog(@"%@",[myArray objectAtIndex:row]);
}

答案 1 :(得分:0)

您可以使用选择器的委托方法

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

{

    if(component==0)
    {
        int i=row;      //here i returns the row selected by you in picker component 0
    }
    else if(component==1)
    {
        int j=row;      //here j returns the row selected by you in picker component 1
    }
    else if(component==2)
    {
        int k=row;      //here k returns the row selected by you in picker component 2
    }

}