I’m having a really weird issue with my custom UITableViewCell. I have a cell with an identifier of “ThreadCell” in Interface Builder with some custom labels. These labels are tagged so I can access them.
In my code, I am doing the following:
static NSString *CellIdentifier = @"ThreadCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: @"ThreadCell"];
}
Person *person = [self.people objectAtIndex: indexPath.row];
UILabel *nameLabel = (UILabel *)[cell viewWithTag: 0];
nameLabel.text = person.nickname;
return cell;
This seems to work fine, with one exception. The TableView draws like this:

This obviously isn’t my custom cell. But the weird thing is, when I tap on a cell, I get this:

This is my custom cell, drawn behind the default cell. What?! I’m not sure how this is happening because I do not ever set the title of the textview anywhere, so I’m not sure where the first John Smith comes from.
Anyone have any ideas?
In your code, you allocate a plain
UITableViewCelland not an instance of your custom cell. Setting areuseIdentifierininitWithStyleis not sufficient to load an instance of a custom cell class.If you develop for iOS 5 and later, then you can use
registerNib:forCellReuseIdentifier:to register a NIB file containing your custom cell.dequeueReusableCellWithIdentifier:will then always return an instance of that NIB.