【发布时间】:2011-09-26 15:20:10
【问题描述】:
我正在实现一个选项卡;我在其中为 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。但它不起作用。
我在做什么?
提前谢谢...
【问题讨论】:
-
什么是cell_object? pickerView 代表如何知道它是什么?如果它是 UITableView 的 Cell,那么您需要在上面的 pickerView 委托中再次创建一个,并使用 viewWithTag 正确获取它们。
-
@Bourne cell_object 是自定义类的对象。- (void)pickerView:(UIPickerView )pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { if (pickerView == myPicker) { if(cell_object.txt_time.tag==0) { cell_object= (Custom_cell2)[table_routine cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; [cell_object.txt_time setText:[NSString stringWithFormat:@"%@",[array_time objectAtIndex:[pickerView selectedRowInComponent:0]]]]; }
标签: iphone uitableview uitextfield uipickerview custom-cell