1

我在情节提要中添加了一个 UITableView,然后使用我的自定义添加一个单元格。单元格返回空白,调试后我发现正在创建的单元格不是我的自定义单元格(我给单元格一个标签 10 来测试它)。

我的代码如下:

UITableViewCell *cell = nil;

static NSString *cellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc]
            initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier ];
}

Food *curFood = [self.mealFoods objectAtIndex:indexPath.row];

/// Get the labels of cell
UILabel *descLabel = (UILabel *)[cell.contentView viewWithTag:101];
UILabel *quantityLabel = (UILabel *)[cell.contentView viewWithTag:102];

descLabel.text = curFood.Description;
quantityLabel.text = [NSString stringWithFormat:@"%f", curFood.Quantity];

return cell;

在我在 ios6 中的最后一个项目中,上述工作正常,但标签不在 contentview 中。或者我上次做了一些我忘记的事情,或者现在在 ios7 中我需要做一些事情来让它使用我的原型/自定义单元?

4

1 回答 1

2

Micantox 在他的评论中是正确的。我错过了在情节提要的自定义单元格中设置单元格标识符:

小区标识符

就我而言,我的标识符只是“细胞”。

于 2013-09-25T14:39:26.653 回答