UICollectionViewCell will be displayed/ was displayed?
16,661
Solution 1
For iOS 8 and higher you can use willDisplayCell of UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
Solution 2
Will:
-[<UICollectionViewDataSource> collectionView:cellForItemAtIndexPath:]
Did:
-[<UICollectionViewDelegate> collectionView:didEndDisplayingCell:forItemAtIndexPath:]
Author by
W Dyson
Web: www.dysonapps.com Twitter: @Dysonapps iTunes: Wesley Dyson
Updated on July 18, 2022Comments
-
W Dyson almost 2 years
pretty simple question.
Is there a notification or delegate-type method to tell when a UICollectionViewCell object is displayed?
-
W Dyson over 9 yearsBeing as iOS 8 is the current release, I'll mark this as correct. Thanks!
-
Chris Prince almost 9 years@Dave DeLong: didEndDisplayingCell refers to the cell being removed from the collection view. From the Apple docs "Tells the delegate that the specified cell was removed from the collection view."
-
Andrew Rozdolsky over 8 years@titaniumdecoy: Actually
collectionView:cellForItemAtIndexPath:
will be called even if some cells were recycled. It's up to you to decide if you want to reuse recycled cell or create a new one inside this method. -
Rauli Rikama about 4 yearsThis doesn't actually tell if it's displayed on screen or not. Cell might be added off screen also. From the documentation: The collection view calls this method before adding a cell to its content. Use this method to detect cell additions, as opposed to monitoring the cell itself to see when it appears.
-
zumzum about 4 yearsthis works for me. It gets called every time the cell comes back in view as I scroll it off and in the view... running iOS 13
-
Zaporozhchenko Oleksandr over 2 yearsit is called before cell will be displayed, not after it displayed.