UICollectionView ScrollToItemAtIndexPath does not work for non visible cells


I am new in iOS and Swift.

Have managed to create a UICollectionView with custom LayoutAttributes and reusable custom cell which calculates the height of it for an image.

The problem that I have is that I want to programmatically scroll to the Nth index but scrollToItemAtIndexPath seems to work only for the visible ones.

When I will scroll manually and then call the code (by using the didSelectItemAtIndexPath collectionView func) it works fine.

Am I missing something here?

many thanks.

Hi @mox8iro,

The apple documentation suggests that scrollToItemAtIndexPath Scrolls the collection view contents until the specified item is visible.

You are on the right track, you simply need to check your code on what you might be missing there.