gpt4 book ai didi

ios - 显示在 Collection View Controller 之间选择的图像

转载 作者:行者123 更新时间:2023-11-28 10:10:31 25 4
gpt4 key购买 nike

我在 First Collection View Controller 中有如下结构

struct Area{
var name = String()
var image = String()
}
var area = [Area]()

并且在第二个 Collection View Controller

struct AreaSelected {
var imageSelected = String()
}
var areaSelected = [AreaSelected]()

我想在 Second Collection View Controller 中显示从 First Collection View Controller 中选择的图像。

所以我这样做是为了将它们导航到位于 didSelectItemAt indexPath 的 Second Collection View Controller

   let indexPaths = self.areaCV!.indexPathsForSelectedItems!
var indexPath = indexPaths[0] as IndexPath
let detailViewController = self.storyboard?.instantiateViewController(withIdentifier: "SVC") as? SecondViewController
detailViewController?.areaSelected = [self.area[(indexPath as NSIndexPath).item]]

他们我得到以下编译器错误

Cannot convert value of type 'Area' to expected element type 'AreaSelected'

如何摆脱这个错误?

最佳答案

基本上

 let selectedArea = self.area[(indexPath as NSIndexPath).item]
detailViewController?.areaSelected = [AreaSelected(imageSelected: selectedArea.name)]

PS:您在不同的 View Controller 中使用不同的(不兼容的)类型,因此绝对不能直接将其分配给彼此。

PSS:在 ViewController 之间的 CellSelected 上设置 segue 更容易、更清晰、更好,并在 func prepare(for segue:UIStoryboardSegue, sender: Any?) 中分配 areaSelected

关于ios - 显示在 Collection View Controller 之间选择的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48993477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com