8

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?

Community
  • 1
  • 1
Paul Peelen
  • 9,588
  • 15
  • 82
  • 162
  • 1
    This isn't a solution to your issue, but please file an enhancement request — via https://bugreport.apple.com — on UICollectionView (iPhone SDK) to support looping content. I put in a similar request not long ago, and Apple **does** read and respond to such requests if there is sufficient demand. – macserv Apr 09 '13 at 21:33
  • I'm not sure what you mean by 'the screen gets truncated' during scrolling. Can you describe a bit more, is this an issue with the view as a whole or the cells? – Wain Apr 13 '13 at 10:39
  • Are you using a custom collection view layout? – Jorge Apr 13 '13 at 16:38
  • 1
    @Wain What I mean is that the screen suddenly becomes empty, even though cells should show content on the screen. It happens randomly. – Paul Peelen Apr 15 '13 at 06:04
  • Confirming the basics, is the truncation related to the content offset reset (shouldn't be random), and how do you decide when to reset (is it arbitrary or at an exact page height of content boundary)? – Wain Apr 15 '13 at 09:22
  • I'm not sure this helps, but EasyTableView seems to achieve what you describe. See this link https://github.com/alekseyn/EasyTableView. – Alex Apr 16 '13 at 20:44

2 Answers2

1

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

Wain
  • 117,132
  • 14
  • 131
  • 151
0

It looks like I am saw reuse visible cells when rotate device. I was fill screen with images from web image search and used fixed dimension to accurate fill UICollectionView bounds for portrait and landscape. But stretching images miss size I set a little, and I saw reused or some more cells when rotate (aka reload data). I'm solve it with calculation current image size just before reload occur (at collectionView:numberOfItemsInSection:) from amount of images I want. Accurate image fit prevent me from extra load and reuse.