Ios UICollectionView显示与选定单元格相关的图像
我有一个CollectionView,我想做的是当有人点击一个单元格时,这个单元格会给你另一个视图,其中显示与所选单元格相关的所有图像我的问题是,我无法评估所有单元格中的哪一个是选定单元格,因此我可以在下一个视图中指定与选定单元格相关的所有图像。我使用的方法出现错误…Ios UICollectionView显示与选定单元格相关的图像,ios,iphone,swift,uicollectionview,Ios,Iphone,Swift,Uicollectionview,我有一个CollectionView,我想做的是当有人点击一个单元格时,这个单元格会给你另一个视图,其中显示与所选单元格相关的所有图像我的问题是,我无法评估所有单元格中的哪一个是选定单元格,因此我可以在下一个视图中指定与选定单元格相关的所有图像。我使用的方法出现错误… let route = segue.destinationViewController as DetailCollectionViewController if let indexPath = collectionView.in
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!。项目,但我强烈建议您仔细阅读。