【问题标题】:cell didn't return nil but it is not displayed单元格未返回 nil 但未显示
【发布时间】:2013-05-27 01:29:56
【问题描述】:

如果这是初学者的问题,我们深表歉意。我正在尝试使用部分和自定义单元格格式填充 UITableView。

我已经调试了这段代码,每个标签上的标签都返回了正确的值:

-(UITableViewCell *)cellForIndexPath:(NSIndexPath *)indexPath forData:(NSObject *)cellData {
static NSString *CellIdentifier = @"MatterWIPCell";

RVMatterWIPExceptionSummary *matterWIPSummary = (RVMatterWIPExceptionSummary *)cellData;

UITableViewCell *cell = [self.searchableTable dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

UILabel *label;

label = (UILabel *)[cell viewWithTag:1];
label.text = [[DataFormat dataFormat] stringLabelFormat: matterWIPSummary.fileNumber];

label = (UILabel *)[cell viewWithTag:2];
label.text = [[DataFormat dataFormat] stringLabelFormat: matterWIPSummary.clientName];

label = (UILabel *)[cell viewWithTag:3];
label.text = [[DataFormat dataFormat] stringLabelFormat: matterWIPSummary.matterTitle];

label = (UILabel *)[cell viewWithTag:4];
label.text = [[DataFormat dataFormat] currencyFormat:matterWIPSummary.workInProgress withDecimals:YES];

label = (UILabel *)[cell viewWithTag:5];
label.text = [[DataFormat dataFormat] stringLabelFormat:matterWIPSummary.matterDescription];

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;

}

我已经检查了它使用相同单元格标识符的情节提要。

我是不是错过了什么,所以即使单元格永远不会返回 nil,数据也不会显示?

谢谢

【问题讨论】:

  • 文本未设置。你必须说cell.textLabel.text = label.text。标签只是坐在那里,而不是单元格的一部分。
  • 但我设置 label = (UILabel *)[cell viewWithTag:];这意味着在情节提要上将值设置为表格视图单元格上的正确标签,不是吗?它适用于其他类,但不适用于本类
  • 您正在使用相同的值制作它的副本,但是它们会更改一个而您不会更改另一个。所以你需要在最后设置它。
  • 我已经尝试使用 cell.textLabel.text = label.text 但它仍然不会出现。
  • 试试这个:注释掉所有的label = (UILabel *)[cell viewWithTag:1]; label.text = [[DataFormat dataFormat] stringLabelFormat: matterWIPSummary.fileNumber]; 行并执行cell.textLabel.text = @"Text"; 或类似的操作,看看会发生什么。

标签: ios uitableview custom-cell


【解决方案1】:

添加 [cell.contentView addSubview:label];在返回单元之前;当然,用这样的东西声明标签 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 320, 25)];

【讨论】:

    猜你喜欢
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-27
    相关资源
    最近更新 更多