TeehanLax / UICollectionView-Spring-Demo

A demonstration of UICollectionView and UIKit Dynamics
MIT License
472 stars 71 forks source link

Breaks down if using variable height cell #11

Open ssfking opened 10 years ago

ssfking commented 10 years ago

Gets super laggy if using variable sized (height) cell, which is pretty common. Seems like PrepareLayout keeps getting called on scrolling, which in turn tries to find the height for EACH one of the 10000 cells...

atomkirk commented 10 years ago

You have to cache the sizes yourself. Here's how I did it:

Then it's super smooth. Just clear the cache before you reload the collection view or insert/delete cells.

njam commented 10 years ago

Experienced a similar problem: basically as soon as we've implemented sizeForItemAtIndexPath the UI would become laggy with many elements (50'000+). It doesn't matter what the implementation looks like though, even if we return a reference to always the same "size" the performance would degrade. If I remove the implementation then performance is good again. cc @fresswolf