skip to Main Content

Im facing issue that is related to scroll to IndexPath after collection view snapshot applied.
For this I have write bellow code

dataSource.apply(snapshot, animatingDifferences: false, completion: {
    self.scrollToIndex(self.visibleIndex)
})

Unfortunately it is not working for me in < iOS 15

Note: Working for iOS 15 and greater versions

2

Answers


  1. You can Use this

    self.collectionView.scrollToItem(at:IndexPath(item: index, section: 0), at: .right, animated: false)
    
    Login or Signup to reply.
  2. Try performing the scroll operation after a short delay:

        dataSource.apply(snapshot, animatingDifferences: false, completion: {
            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + .milliseconds(10)) {[weak self] in
                if let self  = self, let indexToScrollTo = self.visibleIndex {
                    self.scrollToIndex(indexToScrollTo)
                }
            }
        })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search