2011-11-25 63 views
0

有沒有辦法在自定義方法中獲取或設置標準UITableViewCell的textLabel?對於一個僞代碼實例,有沒有辦法從自定義方法中獲取/設置標準UITableViewCell textLabel?

-(void)getTextLabelOfUITableViewCell 
{ 
    UILabel *tempLabel = [[UITableViewCell section:0 row:1] textLabel]; 
} 

-(void)setTextLabelOfUITableViewCell:(UILabel *)data 
{ 
    [[UITableViewCell section:0 row:1] textLabel] = data; 
} 

我試圖與PickerView委託方法綁定這個所以每當我在日期選擇器或選擇器更改值,所選的UITableViewCell將反映這些變化。我不得不創建一個自定義的UITableViewCell。能夠以編程方式使用標準的UITableViewCell樣式會很好。

在此先感謝!

回答

0

您應該保留(或傳遞)對「當前選定單元格」的引用。然後,你可以很容易地通過簡單的寫訪問它的文本標籤:

// assuming the selected cell is kept in a property by name selectedTableViewCell 
UILabel * tempLabel = self.selectedTableViewCell.textLabel; 

如果你想知道如何保持這樣的提法,你應該實現

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; 

方法,並在其中,簡單地狀態:

self.selectedTableViewCell = [tableView cellForRowAtIndexPath:indexPath]; 

這樣,當用戶點擊單元格時,它將被設置爲「選定單元格」。

另一種方式飛行是通過將基準您想從IBAction編輯的文本作爲參數,像這樣的小區:

-(IBAction)getTextLabelOfUITableViewCell:(UITableViewCell *)editMe; 

然後你可以寫類似:

UILabel * tempLabel = editMe.textLabel; 

你幾乎可以做任何你想要的標籤從那裏。

希望這會有所幫助!

+0

非常好,謝謝! – sonoluminescence

相關問題