-[UICollectionView cellForItemAtIndexPath:] doesn't return every cell

Originator:steipete
Number:rdar://29001149 Date Originated:28-Oct-2016 04:45 PM
Status:Open Resolved:
Product:UIKit Product Version:iOS 10.1
Classification: Reproducible:
 
Peter Steinberger28-Oct-2016 04:46 PM

This is also somewhat related to rdar://28999727 and the whole prefetching changes in iOS 10.
Peter Steinberger28-Oct-2016 04:45 PM

Area:
UIKit

Summary:
When asking a collection view for cellForItemAtIndexPath: it does only return cells that are visible and not all cells that are configured. This was fine before cell prefetching became a thing, as these two states basically were identical. Now however this is different.

Steps to Reproduce:
- Open the sample app
- Scroll through the list and notice the different cell colors
- Red means `cellForItemAtIndexPath:` did not return the cell, blue means it did.

Expected Results:
- All cells are blue

Actual Results:
- Depending on scroll speed, most of the non-initial cells are red.

Version:
iOS 10.1

Notes:
This is because in the collectionView:cellForItemAtIndexPath: delegate call I dispatch a configuration event. From what I’ve experienced, this is a pretty common approach to load data asynchronously. The issue arises when that data loads faster than the cell scrolls into the view.

I am aware of the fact that the documentation says `Returns the visible cell object at the specified index path.`, however to me this sounds like a bug. As mentioned above: Previously this was identical with everything that was configured via `collectionView:cellForItemAtIndexPath:` and due to the equal naming of these two methods they really should work hand in hand. So now that prefetching is a thing, the documentation and functionality on this should be changed to make these methods work like counterparts. `cellForItemAtIndexPath:` should return all cells that have been configured by `collectionView:cellForItemAtIndexPath:`.

Configuration:
iPhone 7 Plus

Attachments:
'CollectionViewTest.zip' was successfully uploaded.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!