cell.detailTextLabel.text为NULL

时间:2012-03-20 17:42:06

标签: ios uitableview cell-formatting

我不明白为什么我的cell.detailTextLabel.text为空。

static NSString *CellIdentifier = @"Cell";
//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyId];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    /*[[NSBundle mainBundle] loadNibNamed:@"CellTest2" owner:self options:nil];
    cell = mealPlanCell;*/
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    //self.mealPlanCell = nil;
}

cell.detailTextLabel.text = @"Test";

我可以将cell.textLabel.text设置为值而不是详细信息。

3 个答案:

答案 0 :(得分:1)

我想出了你离开的原因

if(cell == nil){...}

在单元格周围= [[[UITableViewCell alloc] ...

然后单元格将不会重新渲染,因此不会更新样式和/或细节,因此如果删除if(),那么如果要来回更改样式,这将允许您重新渲染表视图中的每个单元格。这不是一件好事,但是如果你考虑它会导致那么它会降低表“速度”,这可能不会引人注意,但它可以考虑作为一个可能的问题。这不是我为解决问题所做的,因为我选择采取不同的方法但是当我尝试时它是有效的。

答案 1 :(得分:0)

我有同样的问题:UITableViewCell initWithStyle:UITableViewCellStyleSubtitle is not working

对于那些搜索并找到这个问题的人......并且遇到与我相同的问题,你在使用原型单元格并且在故事板中没有正确定义样式。

答案 2 :(得分:0)

如果你的rowHeight不够高,即使cell.textLabel.text可见,cell.detailTextLabel.text也不会显示。使用默认字体时,rowHeight为22似乎是最小值。

相关问题