Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionView显示与选定单元格相关的图像_Ios_Iphone_Swift_Uicollectionview - Fatal编程技术网

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

Ios UICollectionView显示与选定单元格相关的图像,ios,iphone,swift,uicollectionview,Ios,Iphone,Swift,Uicollectionview,我有一个CollectionView,我想做的是当有人点击一个单元格时,这个单元格会给你另一个视图,其中显示与所选单元格相关的所有图像我的问题是,我无法评估所有单元格中的哪一个是选定单元格,因此我可以在下一个视图中指定与选定单元格相关的所有图像。我使用的方法出现错误… let route = segue.destinationViewController as DetailCollectionViewController if let indexPath = collectionView.in

我有一个CollectionView,我想做的是当有人点击一个单元格时,这个单元格会给你另一个视图,其中显示与所选单元格相关的所有图像我的问题是,我无法评估所有单元格中的哪一个是选定单元格,因此我可以在下一个视图中指定与选定单元格相关的所有图像。我使用的方法出现错误…

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将为您提供第一个单元格。如果有更多的节,请使用第一个indexPath.section来选择要在哪个节中选择单元格。

indexPath有一个“行”属性,因此indexPath.row==0 indexPath.row==1 etci很抱歉,这是一个集合视图,所以我认为是indexPath.item。但是,当我编写indexPath.item时,我尝试了这个操作,但出现了一个错误。Xcode autocomplete没有将ITEM属性显示为选项:Sah,那么indexPath是可选的吗?您应该仔细阅读选项,它们通常由objective-c的api调用返回,但要快速解决问题,您可以使用Indexath!。项目,但我强烈建议您仔细阅读。