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?
add an 'indexPath` property to the custom table cell. initialize it in cellForRowAtIndexPath. move the tap handler from the view controller to the cell implementation. use the delegation pattern to notify the view controller about the tap event, passing the index path.
A list of indexes that together represent the path to a specific location in a tree of nested arrays.
In Swift, an indexPath is a list of indexes that, together, represent the path to a specific location in a tree of nested arrays. It describes an item's position inside a table view or collection view, storing both its section and its position inside that section.
To Retrieve item index you need to use indexPath.item(for UICollectionView) not indexPath.row(it's for UITableView)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With