【问题标题】:Customise table cell using storyboards使用情节提要自定义表格单元格
【发布时间】:2014-04-01 18:49:32
【问题描述】:

表格单元格的左侧应该有 3 行文本(比如标题、名称、出生日期),右侧应该有 1 行文本大小(分数)。

自动生成行数以及每个单元格的内容。

我尝试在情节提要的原型单元格内创建带有标签的 UILabels 并填充这些标签的文本,但是只显示空单元格而没有内容。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath  *)indexPath
{
  static NSString *CellIdentifier = @"Cell";
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

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

  UILabel *titleLabel = (UILabel *)[cell viewWithTag:100];
  titleLabel.text = list.title;
  UILabel *nameLabel = (UILabel *)[cell viewWithTag:101];
  nameLabel.text = list.name;
  UILabel *dobLabel = (UILabel *)[cell viewWithTag:102];
  dobLabel.text = list.dob;
  UILabel *scoreLabel = (UILabel *)[cell viewWithTag:103];
  scoreLabel.text = list.score;

  return cell;
}

我的代码有什么问题/还有其他解决方案吗?

感谢您的时间和帮助。

【问题讨论】:

    标签: uitableview ios7 storyboard xcode5


    【解决方案1】:

    CellIdentifier 必须与情节提要中的单元格标识符匹配。

    尝试在情节提要的 UITableViewCell 中添加标签并为其自定义文件。这是更好的方法。

    【讨论】:

    • 对!我没有在故事板中设置单元格标识符。谢谢!