-1

在 aUICollectionView中,我正在显示图像并单击它在 ViewController 中打开的图像。工作正常。

但是,当图像在新的 viewController 中打开时,我想将图像向右/向左滑动。

要滑动图像,我尝试CollectionView在单元格中DetailViewController添加和添加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 outlet 无效。Outlets 无法连接重复内容。”

4

1 回答 1

0

对您来说最简单的方法是将整个imgArr作为 collectionView 中的数据源传递给DetailViewController. 然后在 中定义一个selectedName属性DetailViewController并滚动到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)

    }
}
于 2019-08-20T15:10:03.167 回答