2011-09-26 170 views
0

我正在實現一個選項卡;其中我爲其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做。但它不起作用。

我該怎麼辦?

在此先感謝...

+0

什麼是cell_object? pickerView委託如何知道它是什麼?如果它是UITableView的單元格,那麼您需要在上面的pickerView委託中再次創建一個,並使用viewWithTag正確獲取它們。 – Bourne

+0

@Bourne cell_object是定製class.-(無效)pickerView的目的:(UIPickerView *)pickerView didSelectRow:(NSInteger的)行inComponent:如果(NSInteger的)組分 { (pickerView == myPicker){ \t \t如果(cell_object .txt_time.tag == 0) \t \t { \t \t \t cell_object =(Custom_cell2 *)[table_routine的cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0切入口:0]]; \t \t \t [cell_object.txt_time setText:[NSString stringWithFormat:@「%@」,[array_time objectAtIndex:[pickerView selectedRowInComponent:0]]]]; \t \t} – iRavan12

回答

0

簡單的執行是:

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

myArray的是你的UIPickerView數據源。有了上面的代碼,你將能夠調整到你需要做的事情。

相關問題