5

I'm inserting new items as the user scrolls down the collection view... I'm having an issue where if they scroll too fast the collection view stops scrolling when the new items are inserted.

My original issue was that I was just calling self.collectionView.reloadData() instead of performing batch updates but it's currently doing the same exact thing...

This is my code

 let postIndex = self.posts.count
 let newPostIndex = newPosts.count
 let indexArray = (postIndex...postIndex+newPostIndex-1).map{IndexPath(item: $0, section: 0)}

 self.posts.append(contentsOf: newPosts)

  self.collectionView.performBatchUpdates({
           self.collectionView.insertItems(at: indexArray)
                            }, completion: nil)

I already have posts so I create an array of the indexes that I need to update and insert them in the performBatchUpdates but it looks really choppy and lacks a smooth feel.

I tried CATransaction as suggested here https://stackoverflow.com/a/32691888/6513002 and it literally scrolled all the way down completely bypassing everything new and going to the end..

Please assist

Community
  • 1
  • 1
Walker
  • 1,127
  • 15
  • 39

0 Answers0