使用故事板自定义表格单元格

时间:2014-02-28 16:36:26

标签: uitableview ios7 storyboard xcode5

表格单元格左侧应有3个文本行(比如标题,名称,dob),右侧大小(分数)应该有一个文本行。

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

我尝试在故事板中的原型单元格内创建带有标签的UILabel并填充这些标签的文本,但只显示没有内容的空单元格。

- (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;
}

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

感谢您的时间和帮助。

1 个答案:

答案 0 :(得分:0)

CellIdentifier必须与故事板中的单元格标识符匹配。

尝试在故事板和自定义文件中的UITableViewCell中添加标签。这是更好的方式。