iosdevnyc
iosdevnyc

Reputation: 1871

UICollectionView slow scrolling - creating cells

I am looking into collection view working on a project. My scrolling is ver slow for some reason, I think it's because I am doing a lot of processing in my cellForitemAtindex delegate method. Should I have UICollectionView create cells all at once rather then as it's scrolling? Or should can I cache the cells in some array on my own and then load from there as the user is scrolling? These are the only 2 I can think of, is there something else I can do? Thank you for your help.

Upvotes: 0

Views: 1021

Answers (1)

inside cell for item at index path you need to get a cell like this

UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellID" forIndexPath:indexPath];

instead of making it from scratch. If you are using a custom subclass for the cell register it with the collection view by calling registerClass:forCellWithReuseIdentifier:\

You are not in charge of allocating, initializing or caching the reusable cells, the collection view does it for you.

Upvotes: 1

Related Questions