1

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

Rajasekhar Pasupuleti
  • 1,598
  • 15
  • 22

2 Answers2

1

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)
            }
        }
    })
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
Arik Segal
  • 2,963
  • 2
  • 17
  • 29
0

You can Use this

self.collectionView.scrollToItem(at:IndexPath(item: index, section: 0), at: .right, animated: false)