Iterate over all cells in a UICollectionview

I have a UICollection in which there will be a number of student subjects, and each element has a switch inside, used to record attendance. I scan all visible cells like this.

for(attendancecollectionViewCell* cells in [[self collectionView] visibleCells]){ NSLog(@"The switch value : %c",cells.attendanceSwitchLabel.isOn); } 

But I wanted to skip all the cells to visit, not just the visible cells.

+8
uicollectionview uicollectionviewcell
source share
1 answer

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.

+13
source share

All Articles