我已经实现了自定义表格视图单元格。我可以让单元格加载,这不是问题。我正在努力的是设置标签的text属性。我的代码在下面,我做错了什么?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
[self.icaoLabel setTag: 1];
[self.nameLabel setTag: 2];
[self.tafLabel setTag: 3];
[self.metarLabel setTag: 4];
static NSString *CellIdentifier = @"customCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed: @"TAFandMETARCustomCell" owner: self options: nil];
cell = customCell;
self.customCell = nil;
}
// Configure the cell...
TAFandMETAR *taf = (TAFandMETAR *)[tafAndMETARs objectAtIndex: indexPath.row];
//cell.textLabel.text = [dateFormatter stringFromDate: [taf creationDate]];
UILabel *label;
label = (UILabel *)[cell viewWithTag: 1];
label.text = [taf icaoCode];
label = (UILabel *)[cell viewWithTag: 2];
label.text = [taf airfieldName];
label = (UILabel *)[cell viewWithTag: 3];
label.text = [taf taf];
label = (UILabel *)[cell viewWithTag: 4];
label.text = [taf metar];
return cell;
}
感谢。
答案 0 :(得分:1)
假设您的标签是自定义单元格的子视图并且存在于单元格的nib文件中,那么为它们设置标记的最简单方法是直接在IB中执行此操作 - 选择IB中的每个标签并在检查器窗口中设置其标记。