Victor Engel
Victor Engel

Reputation: 2133

How to tell when a UICollectionViewCell disappears

I have a collection view where the cells contain UIImageViews, and I'm trying out adding a label as a subview to these views. The problem is that since the cells are reusable, labels keep getting added. I can, of course, check whether my label already exists and reuse it, but I'd really like to clean up after myself. Is there a way to tell when the cell disappears and remove the label then? I've looked at the various docs and don't find any methods that seem promising. Maybe I'm just missing it.

Upvotes: 6

Views: 8974

Answers (1)

Wain
Wain

Reputation: 119031

Delegate method: collectionView:didEndDisplayingCell:forItemAtIndexPath:

But you should probably just create a custom cell and reuse instead of creating and destroying...

Upvotes: 21

Related Questions