I have a tableview with custom cells via a uitableviewcell subclass. The cells have a label lblResult that changes after a a result is received. It works well, but, when I then scroll down my tableview, other random cells now have that same result label (but they still have their proper “name” label).
I figure this has to do with reuse identifiers, but I’m not sure.
Let me know if you need any more code to understand my problem.
The cell is made like this in cellForRowAtIndexPath
static NSString *CellIdentifier = @"tableCell";
FriendCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[FriendCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:nil];
}
Then before being returned, cell is passed into a loadingQueue dictionary.
When the result loads there is a resultComplete method which loads the cell from the loadingQueue dictionary and the following is called:
[[cell lblNumTagged] setText:[NSString stringWithFormat:@"(%d)",[thisDictionary count]]];
[[cell lblNumTagged] setHidden:NO];
Yes it is because cells are being re-used.
In your custom cell class you can use the prepareForReuse delegate method, which is being called before the cell is being reused and clear the cell’s label there…