Skip to content

Instantly share code, notes, and snippets.

@benvium
Last active September 15, 2015 08:56
Show Gist options
  • Select an option

  • Save benvium/3fd1381546cc454f4dcc to your computer and use it in GitHub Desktop.

Select an option

Save benvium/3fd1381546cc454f4dcc to your computer and use it in GitHub Desktop.
Get the NSIndexPaths for visible rows on a UICollectionView, sorted by row. For some reason [collectionView indexPathsForVisibleItems] returns unsorted items
// Get visible rows and sort them by row
- (NSArray *)sortedVisibleIndexPaths {
NSArray *visibleItems = [self.collectionView indexPathsForVisibleItems];
// visible items is NOT SORTED! lol
NSSortDescriptor *rowDescriptor = [[NSSortDescriptor alloc] initWithKey:@"row" ascending:YES];
NSMutableArray *sortedRows = [[visibleItems sortedArrayUsingDescriptors:@[rowDescriptor]] mutableCopy];
return sortedRows;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment