简体   繁体   中英

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

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.

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

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

Scroll to desired indexPath on completion of snapshot apply action working for me. Here is the code:

dataSource.apply(snapshot, animatingDifferences: false) { in
     /// Scroll to indexPath action.
}

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM