4
votes

When I try to refresh the data in my UICollectionView that's using iOS 13's new compositional layout, I can't find a way to make horizontally scrolling sections scroll back to their starting point.

If I call applySnapshot on the data source, the section's data refreshes, but it doesn't scroll back to the beginning. If I call scrollToRowAtIndexPath on each section, it will go back to the first row but it ignores the content insets on that section, which doesn't look good.

I tried applying an empty snapshot before applying the real one and that does work, but I intermittently get crashes in UICollectionCompositionalLayoutSolver saying "invalid section - null".

So what's the proper way to reset the horizontal scrolling on a collection view that's using compositional layout? I'm sure there's something I'm missing.

1

1 Answers

-2
votes

I am not sure about your question in detail, but I am doing an initial scroll to the current object using this method, that does beautifully center the scroll to object:

collectionView.scrollToItem(at: IndexPath(item: indexOfCurrent, section: sectionIndex), at: .centeredHorizontally, animated: true)