Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looping through all cells in UICollectionView

I have a UICollectionView and i want to add animation to each cell.

Currently I'm using

for(UICollectionView *cell in collectionView.visibleCells){
  //add animation to cell here
}

But that only applies the animation to the visible cells and as soon as i scroll down and the cell is no longer visible the animation stops.

How do i loop through all the cells in the UICollectionView?

like image 964
user1838169 Avatar asked Apr 05 '13 09:04

user1838169


1 Answers

I would go about this in a different way, probably. If you want the cells to animate, you could set a property shouldAnimate = YES. Then in your collectionView:cellForItemAtIndexPath: check that property and apply the animation if needed (or remove it).

After setting the property, reload only the visibleCells: [collectionView reloadItemsAtIndexPaths:collectionView.indexPathsForVisibleItems].

Now, since the animation is provided when a cell is requested through the Datasource-Protocol, you also get the animation when you scroll.

like image 178
fguchelaar Avatar answered Oct 04 '22 04:10

fguchelaar