![](/img/trans.png)
[英]passing data from one collectionView cell to other collection view controller in swift 4 by sending “ID” as a parameter
[英]Passing data from one collectionView to other collectionView
在UICollectionView
,我正在显示图像并单击它在 ViewController 中打开的图像。 工作正常。
但是,当图像在新的 viewController 中打开时,我想向右/向左滑动图像。
为了滑动图像,我尝试在DetailViewController
添加一个CollectionView
并在单元格内添加UIImageView
。
//on clicking the image from main view controller
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let vc = storyboard?.instantiateViewController(withIdentifier: "DetailViewController") as? DetailViewController
vc?.name = imgArr[indexPath.row]
self.navigationController?.pushViewController(vc!, animated: true)
}
错误是:
“非法配置:从 DetailViewController 到 UIImageView 的 img 插座无效。插座不能连接到重复的内容。”
最简单的方法是将整个imgArr
作为DetailViewController
collectionView 的数据源传递。 然后在DetailViewController
定义selectedName
属性并在DetailViewController
出现之前滚动到所选名称。
编辑:
//on clicking the image from main view controller
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let vc = storyboard?.instantiateViewController(withIdentifier: "DetailViewController") as? DetailViewController {
vc.imgArr = imgArr
vc.selectedNameIndex = imgArr[indexPath.row]
self.navigationController?.pushViewController(vc, animated: true)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.