2013-05-05 58 views
2

創造了我的UITableViewController在我的故事板我創建了一個自定義單元格,有幾個文本標籤,我要代表我的記錄不同的數據。如何選擇不同的文本標籤(我設置了每個標籤,我想用不同的標籤進行更改,但不確定從哪裏開始)要更改。在自定義訪問textlabels的UITableViewCell在故事板

回答

5

你可以用標籤做到這一點,但我通常喜歡用的UITableViewCell的自定義子類來做到這一點。您只需要在自定義類的.h文件中定義一些IBOutlets - 在.m文件中根本不需要任何代碼。將單元格的類更改爲您的子類,並將插口連接到單元格中的標籤。然後在代碼中,您可以像引用標準單元一樣引用它們。如果您的出口均label1和label2,則:

cell.label1.text = .... 
cell.label2.text = ... 

如果你想使用代碼,那麼你可以使用的方法,viewWithTag:去標籤的參考。

UILabel = *aLabel = (UILabel *)[cell.contentView viewWithTag:1]; 
+0

謝謝!然而,我的tableview中的單元格變成空白。 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath :(NSIndexPath *)indexPath { static NSString * CellIdentifier = @「InfoCell」; SearchCell * cell =(SearchCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 如果(細胞==無) { 細胞= [[SearchCell的alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } //配置單元格... Record * record = [self.workingDatabase objectAtIndex:indexPath.row]; – dkirlin 2013-05-06 02:39:36

+0

//設置內容 cell.myName.text = record.ABName; cell.myTarget.text = record.ABTarget; cell.myVendor.text = record.ABVendor; cell.myCatNumber.text = record.ABCatNumber; cell.myClonality.text = record.ABClonality; cell.myOrganism.text = record.ABSourceOrg; return cell; } – dkirlin 2013-05-06 02:40:09

+0

@NLDK,如果你記錄cell.myName或cell.myTarget等,他們是否返回一個UILabel而不是零? – rdelmar 2013-05-06 02:48:06