簡體   English   中英

如何在表格視圖中固定自定義單元格的文本字段的標記值?

[英]How fixed tag value for text field of custom cell in table view?

我正在實現一個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。 但這是行不通的。

我所做的 ?

提前致謝...

一個簡單的實現是:

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

myArray是您的UIPickerView的數據源。 使用上面的代碼,您將能夠將其調整為所需的操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM