You cannot iterate over invisible cells because these cells do not exist. A UICollectionView, like a UITableView, reuses cells as soon as they are off-frame. If you scroll down, it will take the cell that was scrolled and use it for the βnewβ cell that should be scrolled into view.
If you want to save the state for the record in your collection, you will have to store it separately from the cell itself. For example, NSArray structures (or custom NSObjects) that map to the value of indexPath.row.
A more important question for you would be: what are you trying to achieve in your for loop?
Let me know if you need more information or sample code.
Zak arntson
source share