我在情节提要中添加了一个 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 中我需要做一些事情来让它使用我的原型/自定义单元?