如何固定表视图中自定义单元格文本字段的标签值?

发布于 2024-12-06 17:01:46 字数 1039 浏览 1 评论 0原文

我正在实现一个 tab;e,其中我为 tableview 的单元格创建了一个自定义单元格。在自定义单元格上,我显示两个文本字段、一个按钮和一个图像视图。现在我想在文本字段上实现一个事件。那是当我单击文本字段然后出现选择器视图时。借助选择器视图,我们可以更改文本字段的文本。我已经应用了事件,就像当我们单击文本字段然后出现选择器视图时一样。但是当我滚动选择器视图时,文本字段值不会改变。那么我要做什么才能让它发生呢? 在表视图中,我有 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。但它不起作用。

我做什么 ?

提前致谢...

I am implementing a tab;e in which i have created a custom cell for cell of tableview. On custom cell i am displaying two text field , one button and one image view. Now i want implement an event on text field. That is when i click on text field then appear picker view. With the help of picker view we can change text of text field. I have applied event like as when we click on text filed then appear a picker view. But when i scroll picker view then text field value not changing. so what i will do so that it happens?
In table view i have 10 rows and i want to insert value from single picker view. I have also set tag on text field of custom cell by using this code.

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

for selection value from picker view i use this code...

 - (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]]]];
       }
    }
} 

I have do for 10 rows text.tag. But it is not working.

What i do ?

Thanks in advance...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

隔纱相望 2024-12-13 17:01:46

一个简单的实现是:

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

myArray 是 UIPickerView 的数据源。使用上面的代码,您将能够将其调整为您需要执行的操作。

A simple implementation would be:

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

myArray is the datasource for your UIPickerView. With the above code you will be able to tweak it to what you needed to do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文