gpt4 book ai didi

ios - 使用 UICollectionView 继续

转载 作者:行者123 更新时间:2023-11-28 12:13:56 24 4
gpt4 key购买 nike

所以我有一个带有 CollectionView 和自定义 Cell 的 TableViewController,但我想准备一个从 CollectionView 到 TableView 的 segue。

我试过这个:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

if segue.identifier == "drawSegue" {
let dst = segue.destination as! DrawerViewController

guard let indexPath = cupCollectionView.indexPathsForSelectedItems else{
return
}
dst.cup = cupboards[indexPath.row] as! Cupboard
}
}

但是我得到一个错误Value of type '[IndexPath]' has no member 'row'。还有另一种方法吗?因为在另一个项目中,我从一个 tableView 到一个 tableView 使用了它并且它有效......

这是我的收藏 View :

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return cupboards.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cupCell", for: indexPath) as! CupboardCollectionViewCell

let cupboard = cupboards[indexPath.row]

cell.cupLabel.text = cupboard.name

return cell
}

提前致谢

最佳答案

看起来像cupCollectionView.indexPathsForSelectedItems正在返回一个 IndexPath 对象数组,因此不是访问单个 IndexPath.row你想调用 Array<IndexPath>.row不存在

在你的didSelectCell当你调用 performSegue ,将您的单元格添加为发件人,然后您可以将其更改为let indexPath = cupCollectionView.indexPath(for: sender)

关于ios - 使用 UICollectionView 继续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47519651/

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