0

我正在实现一个选项卡;我在其中为表格视图的单元格创建了一个自定义单元格。在自定义单元格上,我显示两个文本字段、一个按钮和一个图像视图。现在我想在文本字段上实现一个事件。那是当我单击文本字段然后出现选择器视图时。在选择器视图的帮助下,我们可以更改文本字段的文本。我已经应用了事件,就像我们单击文本字段然后出现选择器视图一样。但是当我滚动选择器视图时,文本字段值不会改变。那么我会怎么做才能让它发生呢?在表视图中,我有 10 行,我想从单个选择器视图中插入值。我还使用此代码在自定义单元格的文本字段上设置了标签。

cell_object.txt_time.tag=[indexpath.row];

对于选择器视图中的选择值,我使用此代码...

 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent: (NSInteger)component
{
    if (pickerView == myPicker)
    {
         if(cell_object.txt_time.tag==0)
           {
        [cell_object.txt_time setText:[NSString stringWithFormat:@"%@",[array_time objectAtIndex: [pickerView selectedRowInComponent:0]]]];
       }
      else if(cell_object.txt_time.tag==1)
           {
        [cell_object.txt_time setText:[NSString stringWithFormat:@"%@",[array_time objectAtIndex: [pickerView selectedRowInComponent:0]]]];
       }
    }
} 

我已经做了 10 行 text.tag。但它不起作用。

我做什么 ?

提前致谢...

4

1 回答 1

0

一个简单的实现是:

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent(NSInteger)component{
    NSString *string = [[NSString alloc] initWithFormat:@"%@",[myArray objectAtIndex:row]];
    textfield.text = string;
}

myArray 是 UIPickerView 的数据源。使用上面的代码,您将能够将其调整为您需要做的事情。

于 2011-10-03T13:23:15.307 回答