gpt4 book ai didi

ios - 我如何从我的父 UICollectionViewCell 检索我的子 UICollectionView 中的数据 - swift 4

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

假设我有一个 ParentCollectionViewController,它具有名为 assetID 的数据。

此数据在 ParentCollectionViewControllerCell 中也可用。

如何在位于每个 ParentCollectionViewControllerCell 中的 ChildCollectionView 中传递此数据。

Here's the image

谢谢!

最佳答案

首先,如果你想先发送数据,你需要在ParentCollectionViewControllerCell中注册子collectionviewcell。您将在 awakeFromNib() 中执行此操作。

override func awakeFromNib() {
childCollectionView.register(UINib.init(nibName: "childCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "childCollectionViewCell")
childCollectionView.reloadData()
}

所以这意味着您在 ParentCollectionViewControllerCell 中拥有子 collectionview 的所有委托(delegate)和数据源。因此,您将通过 cellForItemAtindexPath 发送数据:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "childCollectionViewCell", for: indexPath) as! childCollectionViewCell
cell.bindAssetid(strAssetId: assetID!)
return cell
}

我认为这个答案满足了您的要求。

快乐编码

关于ios - 我如何从我的父 UICollectionViewCell 检索我的子 UICollectionView 中的数据 - swift 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54409635/

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