I have a UINavigationController full of UITableViews and I use custom cells in a specific one of these.
In tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath I add a UILabel with [cell addSubview:label];
This works great, however if I then go into the detail view, then return back, it duplicates the label. How can I stop this?
Thanks.
The problem is that you are adding a new label every time the cell gets reused and displayed again.
Since you’re using a custom cell already, the easiest solution would be to give the cell a
UILabelproperty, and use that instead of adding a new label each time. Specifically, you should only add a new label if you’re creating a cell instead of getting a recycled one. Or, you could add a newUILabelonly if the property is nil.