Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

looping through all cells in UICollectionview

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.

like image 362
Ayan Avatar asked Apr 20 '13 19:04

Ayan


1 Answers

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.

like image 157
Zak Arntson Avatar answered Sep 21 '22 18:09

Zak Arntson