Reputation: 69
I have a CollectionView and what I want to do is when someone taps on one cell, this cell takes you a another view where it shows you all images related to the selected cell. My problem is that I am having trouble evaluating which one of all my cells is the selected cell, so I can assign in the next view all images related to the selected cell. I get an error with my the approach I am using...
Upvotes: 0
Views: 433
Reputation: 505
indexPath.row is giving you the first cell. If you have more sections, use first indexPath.section to choose in what section you are selecting the cell.
Upvotes: 0
Reputation: 6377
let route = segue.destinationViewController as DetailCollectionViewController
if let indexPath = collectionView.indexPathsForSelectedItems()?.first as? NSIndexPath {
switch indexPath.item {
case 0:
route.passedArray = detailCollection1
case 1:
route.passedArray = detailCollection2
default:
break
}
}
/* for multiple selection
// iterate over the indexPathsForSelectedItems if it is not nil
for indexPath in collectionView.indexPathsForSelectedItems() as [NSIndexPath] {
// do your wok
}
*/
Upvotes: 1