skip to Main Content

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.

3

Answers


  1. Chosen as BEST ANSWER

    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.


  2. 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

    Login or Signup to reply.
  3. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search