Nirma Nirma - 1 month ago 26
iOS Question

How to properly get index from index path in a UICollectionView?

I have a one dimensional array of images that I am feeding to a UICollectionView.
The collection view is just one section composed of the elements in the array.
when I click a cell and

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath;
gets fired off and I do a print out of the indexPath I get values like [0,0] for element 0 in row 0 but then the very next element in that row is [0,5].

How can I map the indexPath to my array like the way
UITableView
's [indexPath row] matches directly to the corresponding index?

Answer

I've never used them, but my understanding is that the two properties of a UICollectionView's indexPath are section and item, not section and row like in a UITableView.