Rajasekhar Pasupuleti
Rajasekhar Pasupuleti

Reputation: 1658

How to scroll to an IndexPath after apply the snapshot

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

Upvotes: 1

Views: 1191

Answers (2)

Arik Segal
Arik Segal

Reputation: 3031

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)
            }
        }
    })

Upvotes: 1

Pankaj Teckchandani
Pankaj Teckchandani

Reputation: 745

You can Use this

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

Upvotes: 0

Related Questions