我已经完成了我的研究并遵循了这个过程的众多指南,包括:
但是后续问题中反复出现的主题始终是“TableViewCells 出现了,但它们是空的”。我假设人们解决了这个问题,但没有发布任何解决方案。
因此,我所处的阶段包括:静态单元格显示并正确填充数据,动态单元格正确显示数量,但不显示其元素(它们是空的)。
我相信我已经正确连接了所有内容。我有:
- 在我的 UITableViewController 子类中,包含并覆盖了上面两个链接中标记为“Answer”的所有必需方法。
- 子类化 UITableViewCell,并在子类中包含两个 UILabel 属性。
- 将 Storyboard 中单元格的类设置为我的子类,并给定一个适当的标识符,该标识符在 Controller 子类中正确使用。
- 在情节提要的单元格上放置了两个 UILabel。
- 将两个标签连接到 Cell 子类中的属性。
我实例化并为属性赋值,就像上面的答案一样。
static NSString *CellIdentifier = @"DynamicCell";
OwnersInfoEventsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[OwnersInfoEventsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.eventName.text = @"Name"; //this doesn't show up
cell.eventNeed.text = @"Need"; //this doesn't show up
cell.backgroundColor = [UIColor redColor]; //this works, the cell shows up red
return cell;
我错过了什么?