I've got a custom UITableViewCell implementation (leveraging labels as subviews) that is rendering the list of items correctly, but when I scroll down and select an item (say number 43 of 100), I see a rendering of a cell from earlier in the list (from say, number 3 on the first render page in the table) appear on top of the cell I selected.
Here is my method:
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// index of table view correlates to index of array
Card *card = [cards objectAtIndex:indexPath.row];
UILabel *cardNameLbl = [[[UILabel alloc] initWithFrame:CGRectMake(10.0, 3.0, 200.0, 18.0)] autorelease];
cardNameLbl.tag = CARD_NAME_TAG;
cardNameLbl.text = card.name;
cardNameLbl.font = [UIFont systemFontOfSize:12.0];
cardNameLbl.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:cardNameLbl];
UILabel *cardNumLbl = [[[UILabel alloc] initWithFrame:CGRectMake(10.0, 21.0, 100.0, 18.0)] autorelease];
cardNumLbl.tag = CARD_NUM_TAG;
cardNumLbl.text = card.number;
cardNumLbl.font = [UIFont systemFontOfSize:12.0];
cardNumLbl.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:cardNumLbl];
UILabel *cardTypeLbl = [[[UILabel alloc] initWithFrame:CGRectMake(110.0, 21.0, 200.0, 18.0)] autorelease];
cardTypeLbl.tag = CARD_TYPE_TAG;
cardTypeLbl.text = card.type;
cardTypeLbl.font = [UIFont systemFontOfSize:12.0];
cardTypeLbl.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:cardTypeLbl];
UILabel *cardQuantityLbl = [[[UILabel alloc] initWithFrame:CGRectMake(250.0, 3.0, 50.0, 18.0)] autorelease];
cardQuantityLbl.tag = CARD_QUANTITY_TAG;
cardQuantityLbl.text = [NSString stringWithFormat:@"%d", card.have];
cardQuantityLbl.font = [UIFont systemFontOfSize:12.0];
cardQuantityLbl.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:cardQuantityLbl];
return cell;
}