UItableViewCell with old content

I had a UITableView that had relatively simple cells. So simple in fact that I didn’t want to bother with subclassing UITableViewCell to draw up content. The cell had two UILabels and one UIImageView.
The problem however derived from reusing the cell – when drawing transparent PNG images into that cell, older data was still present and visible in new cells. This meant that I had to somehow clear the cell from old content.
This is how it can be done. Add the following just before creating new content:

for (UIView *view in cell.contentView.subviews) {
 [view removeFromSuperview];

This clear the contentView from old content and you can start adding new.

image © jeffk42

One thought on “UItableViewCell with old content

  1. Yo.

    Didn’t work. Although, if I changed from cell.contentView.subviews to cell.subviews it did.

    Well, thanks anyway for guiding me in the right direction.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s