static NSString *cellID = @"Cell Identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell.contentView setBackgroundColor: [UIColor clearColor]];
UIImage * box = [UIImage imageNamed: @"box.png"];
UIView * cellbackgroundview = [[UIView alloc] initWithFrame: CGRectMake(7, 0, box.size.width, box.size.height)];
[cellbackgroundview setBackgroundColor: [UIColor colorWithPatternImage: box]];
UILabel * nameLabel = [[UILabel alloc] initWithFrame: CGRectMake( 0, 15, box.size.width, 19.0f)];
nameLabel.text = name;
[nameLabel setTextColor: [UIColor colorWithRed: 79.0f/255.0f green:79.0f/255.0f blue:79.0f/255.0f alpha:1.0f]];
[nameLabel setFont: [UIFont fontWithName: @"HelveticaNeue-Bold" size: 18.0f]];
[nameLabel setBackgroundColor: [UIColor clearColor]];
nameLabel.textAlignment = NSTextAlignmentCenter;
nameLabel.tag = 1;
.....
}
((UILabel *)[cell viewWithTag:1]).text = name;
((UILabel *)[cell viewWithTag:2]).text = pitch;
为什么像我上面那样使用 viewWithTag 是有效的?