cell.detailTextLabel.text是NULL

我不明白为什么我的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设置为一个值,但不是细节之一。

如果你离开,我找出原因

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

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

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

我有同样的问题: UITableViewCell initWithStyle:UITableViewCellStyleSubtitle不起作用

对于那些search和发现这个问题的人来说,和我有同样的问题,你在哪里使用原型单元格,而且在故事板中没有正确定义样式。

如果rowHeight不够高,即使cell.textLabel.text可见,cell.detailTextLabel.text也将不可见。 22的rowHeight似乎是默认字体的最小值。

Interesting Posts