对于我的集合视图我用didSelectItemAt
打电话performSegue
。我的问题是发件人是我的vc,而不是单元本身。因此,在prepareForSegue中,出现错误,因为我无法将vc转换为单元格类型。
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
performSegue(withIdentifier: "collectionSegue", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destinationVC = segue.destination as? ImageViewController {
let cell = sender as! ImageCollectionViewCell
let indexPath = imageCollectionView.indexPath(for: cell)
destinationVC.buttonTag = indexPath?.row
}
}
您可以将发件人设置为任意内容。这可能会有所帮助:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView!.cellForItemAtIndexPath(indexPath) as! ImageCollectionViewCell
performSegue(withIdentifier: "collectionSegue", sender: cell)
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句