我想使用標籤名稱顯示單元格標籤文本。在默認單元格中的主要板子中,我添加了一個標籤,並將標籤名稱添加爲70.我正在嘗試使用以下方法加載該數據。沒有顯示。請幫幫我。ViewwithTag不獲取單元格標籤
[Crop Cropname] is not empty, cell.textLabel.text = [crop cropName] works fine.I am just trying to format things.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell...
Crop * crop = [filteredItemist objectAtIndex:[indexPath row]];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d",crop.cropId];
UILabel *cropNameLabel = (UILabel *)[cell viewWithTag:70];
cropNameLabel.text = [crop cropName];
return cell;
}
如果您在StoryBord中創建了單元格,那麼只能使用該單元格。 –
當我添加一個tableview控制器時,在故事板中創建了一個默認單元格。如果我使用cell.textLabel.text填充數據,單元格工作正常。 viewwithtag沒有做任何改變一些如何。 – user2569524
你正在做錯的方式。如果你在xib中添加TableView,它將會沒有單元格。因此,最好單獨創建單元格,並添加UILabel,然後在'cellForRowAtIndexPath'中使用該單元格,不要再在'cellForRowAtIndexPath'中初始化任何單元格。 –