如何固定表视图中自定义单元格文本字段的标签值?
我正在实现一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个简单的实现是:
myArray 是 UIPickerView 的数据源。使用上面的代码,您将能够将其调整为您需要执行的操作。
A simple implementation would be:
myArray is the datasource for your UIPickerView. With the above code you will be able to tweak it to what you needed to do.