Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add indexTitles in a collection view? (iOS 10+)

As the question, I'm trying to add an "index titles" in a collection view for a fast navigation of the contents of my UIColletionView.

I've read that, starting from iOS 10, method like indexTitles(for:) and collectionView(_:indexPathForIndexTitle:at:) can help me in that as in the UITableViews. But I'm not getting any result! Have you figured out how to use those methods? Thanks in advance for any help.

like image 616
Alessandro Francucci Avatar asked Mar 08 '23 09:03

Alessandro Francucci


1 Answers

If you look at UICollectionView.h, indexTitlesForCollectionView is only available in tvos:

/// Returns a list of index titles to display in the index view (e.g. ["A", "B", "C" ... "Z", "#"])
- (nullable NSArray<NSString *> *)indexTitlesForCollectionView:(UICollectionView *)collectionView API_AVAILABLE(tvos(10.2));

You might have read Apple's documentation, which states that indexTitle methods are available for iOS 10.3+ and tvOS 10.2+: https://developer.apple.com/documentation/uikit/uicollectionviewdatasource/2851455-indextitles

I tried implementing it on iOS and it just doesn't work, which leads me to believe that somehow they made a mistake in the documentation.

like image 154
nambatee Avatar answered Mar 15 '23 08:03

nambatee