Home > Software design >  iOS - Is there any method that will call after collection view loaded (set layout, set datasource)
iOS - Is there any method that will call after collection view loaded (set layout, set datasource)

Time:12-22

I want to perform scroll to particular index path after collection view load complete. Is there any method that inform the collection view is loaded (set layout, set datasource)

NOTE: Im using DiffableDatasource to display collection view. I tried .apply snapshot completion - not working for me.

CodePudding user response:

Please check where are you calling you collectionView.reloadData() lastly. after that line, you can simply call this.

self.collectionView.scrollToItem(at:IndexPath(item: indexNumber, section: sectionNumber), at: .right, animated: false)

For reference, visit this link. How to scroll to a particluar index in collection view in swift

CodePudding user response:

In swift collectionView comes with scrollView property and that you can use to scroll to the particular item's index

yourCollectionView.scrollToItem(at: desiredIndexPath, at: UICollectionView.ScrollPosition, animated: false)

for more information please go through this documentation

  • Related