Sha Sha - 5 months ago 31
Objective-C Question

Getting first Cell/Item of UICollectionView while scrolling - iOS

I have a

with 1 row 1 column. I want to get the first item (
basically) when I am scrolling it horizontally.

For example, I have got 100 items displayed horizontally in my
and when I scroll from right to left, whichever item is the first one visible, I need its
Which means the
will be constantly changing while its scrolling.

How to achieve this? Please Guide. Thanks!


collectionView.indexPathsForVisibleItems() returns an array of NSIndexPath for visible cells. You can get the left most one by sorting them by NSIndexPath.item.

Edti: To be notified while scrolling, implement the UIScrollViewDelegate method scrollViewDidScroll(_: UIScrollView). Remember that UICollectionView is a subclass of UIScrollView.