简体   繁体   English

UICollectionView显示与所选单元格相关的图像

[英]UICollectionView showing images related to the selected cell

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. 我有一个CollectionView,我要做的是当有人轻按一个单元格时,该单元格带您进入另一个视图,该视图向您显示与所选单元格相关的所有图像。 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... 我使用的方法出现错误...

在此处输入图片说明

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
}

*/

indexPath.row is giving you the first cell. indexPath.row给您第一个单元格。 If you have more sections, use first indexPath.section to choose in what section you are selecting the cell. 如果有更多部分,请使用第一个indexPath.section来选择要在哪个部分中选择单元格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM