I have UICollection in which there will be number of Students items and each item having switch inside it used for recording attendance. I am loop through all visible cells like this.
for(attendancecollectionViewCell* cells in [[self collectionView] visibleCells]){
NSLog(@"The switch value : %c",cells.attendanceSwitchLabel.isOn);
}
But, I wanted to loop through all the cells for attendance, not just the visible cells.
You cannot loop through non-visible cells because those cells don't exist. UICollectionView, like UITableView, reuses cells as soon as they are offscreen. I.e., if you scroll down, it takes a cell that has been scrolled off and uses it for a "new" cell about to be scrolled into view.
If you wish to hold state for an entry in your collection, you'll have to store it separately from the cell itself. For example, an NSArray of structs (or custom NSObjects) that map to the indexPath.row value.
A more important question for you specifically would be: What are you trying to achieve in your for loop?
Let me know if you need more information or sample code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With