Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView infinite scroll: reuses index paths and clears content

Using the answer from a previous question, I made an infinite scroll. However, I have a problem when scrolling.

It seems that for a millisecond, the UICollectionView (or maybe the UIScrollView for that matter) thinks the cells shown are not visible anymore, thus reuses the cells for new cells. This leads to cells being double used when scrolling. The reason I believe this is the cause of my problem is because the "cheat" one uses in order to be able to infinite scroll is to reset the contentOffset of the UIScollView.

The cells of my UICollectionView contain a background image which is downloaded asynchronously (of fetched from cache) using MKNetworkKit. One of the other side effects is that when scrolling a view "screen lenghts" in a row, the screen gets truncated. Almost as if a reloadData occurred in the UIScrollView, yet the code doesn't reload the data at all.

My question is: How can I prevent the UICollectionView from reusing visible cells and from truncating the view suddenly?

like image 468
Paul Peelen Avatar asked Apr 09 '13 19:04

Paul Peelen


1 Answers

Have 2 reuse identifiers. When you reset the contentOffset toggle between them.

like image 107
Wain Avatar answered Nov 03 '22 21:11

Wain