Does anyone have suggestions on how to purge a cached UITableViewCell
?
I'd like to cache these cells with reuseIdentifier. However, there are times when I need to delete or modify some of the table rows. I expect to call reloadData
after the row changes.
Right now, dequeueReusableCellWithIdentifier
always returns the cached(obsolete) entry from before. How do I indicate that the cache is stale and needs to be purged?
The old data from previous usage of the cell should be cleared with the message
prepareForReuse
. When a cell is dequeued this message is sent to the cell before it is returned fromdequeueReusableCellWithIdentifier:
.I don't know how to purge the cache, however, I use a workaround how to handle the situation, when the rows need to be changed.
First of all, I don't use static cell identifier. I ask the data object to generate it (pay attention to
[myObject signature]
, it provides a unique string describing all needed properties):[myObject signature]
provides different signatures for different list of properties. So, if my object is changed, I just call[self.tableView reloadData]
, myObject will provide a new signature, and the table load a new cell for it.[myObject configureCell:cell]
places all needed subviews to the cell.[myObject updateCellWithData:cell]
updates the subviews of the cell with current data.