How to speed up UICollectionView cell rendering in tvOS

390 Views Asked by At

I have developed a tvOS application that renders a CollectionView inside of a CollectionView. Each section of the first CollectionView has only 1 element, let's call it RowCell, and this element contains the second CollectionView, that has many cells of that given category.

The problem I have is: when I use .reloadData() in the prepareForReuse method in the RowCell (the row that contains the cells separated by categories) it loads extremely slow when I scroll up and down. And if I don't use .reloadData() for the RowCell, the data always get rendered wrong.

Any thoughts about how to use .reloadData() and don't decrease scrolling/rendering speed.

Thanks in advance.

2

There are 2 best solutions below

0
alanpaivaa On

It seems that if you have many categories, you're doing a lot of reloadData(). That gets worse if the inner collection view's cells requires hard work to be rendered, despite of cell reusing. To mitigate that, you may want to take a look in Prefetching Collection View Data, where you can prefetch required data and perform hard work asynchronously for cells before they actually display.

Also, if that's possible, I suggest you to take a look in IGListKit, a third-party library developed by Instagram that claims to be a tool for building flexible and fast lists. I myself used IGListKit and it is, indeed, a really good option for creating the kind of collection view you want. The problem is that its learning curve can be steep.

Hope this helps!

0
gabrielrf97 On

There were two simple problems with it. First, every cell was loading heavy images from the internet, so I request for lower quality alternatives in the API and the second one is that these images were not being saved in Cache, so I had to do it every in every user scroll. By implementing both of these solutions, all problems went away.