0

I'm trying to set up a particularly large UICollectionView, and I'm embedding it within a UIScrollView (as per this answer to another question on SO) in order to support scrolling in both directions. I've got it up and running, everything is working perfectly, except that performance takes a HUGE hit as the size of the CollectionView grows.

After some hunting around, I was able to figure out the problem: because that SO answer calls for the CollectionView to be resized so that all the cells are visible at once, "dequeuing" isn't a thing anymore. The CollectionView within the ScrollView has dimensions of 2000x2000 (or whatever), so even though the ScrollView is just the size of the screen and only shows 20 cells or so at a time, the CollectionView thinks all cells are visible and needed right now. Thus, every cell in the CollectionView is generated at once, meaning the page takes a ludicrously long time to appear.

Is there a way to communicate to the CollectionView which cells are currently visible through the ScrollView, so it doesn't generate unnecessary cells and dequeues them as normal? Or if not, is there a way to make a CollectionView that scrolls diagonally, but that doesn't have this problem?

Community
  • 1
  • 1
Nerrolken
  • 1,884
  • 3
  • 22
  • 49
  • 1
    I think you relied on a poor answer for the original design. The correct answer to this question is the better way to get a performant, infinite 2D collection view: http://stackoverflow.com/questions/15549233/view-with-continuous-scroll-both-horizontal-and-vertical/15553973#15553973 – danh Sep 03 '14 at 02:31
  • Oof, there goes a good amount of work. Well, fair enough. Thanks for suggesting an alternative, at least! :) And do you know, does that suggested answer scroll diagonally (i.e. vertically and horizontally at the same time), or just vertically and horizontally independent of each other? I don't need it to be infinite, I just need it to move in any direction and support a large number of total cells. – Nerrolken Sep 03 '14 at 02:39
  • 1
    Yes, I believe it does scroll in both dimensions simultaneously. (I built one a little while back using the essentially the same trick. You'd have to try to make it not scroll in both dimensions at the same time). – danh Sep 03 '14 at 02:45
  • Awesome. Well if you want to put that as an answer, I'll accept it. Otherwise, thanks again! – Nerrolken Sep 03 '14 at 02:46

0 Answers0