gpt4 book ai didi

swift - 在多个 UICollectionViewCell 之间传递数据

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

我得到了一个包含 2 个不同部分的 Collection View 。我想点击其中一个部分中的一个单元格并将该单元格中的文本传递给 TextView ,该 TextView 位于其自己部分的单独单元格中。

到目前为止,这是我尝试过的方法,但没有任何反应。我正在尝试将笔记数据发送到另一个单元格。我可以在点击单元格时打印数据。

已更新:这是我要将所选单元格数据传递到的带有 TextView 的单元格。

// cell that I am trying to passing data to
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = myCollectionView.dequeueReusableCell(withReuseIdentifier: "notesView", for: indexPath) as! TestViewCollectionViewCell
cell.myTextView.text = .....

return cell
}


// Cell that I am passing data from
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if indexPath.section == 0 {
// Cell that I want to send data to
let cell = myCollectionView.dequeueReusableCell(withReuseIdentifier: "notesView", for: indexPath) as! TestViewCollectionViewCell

let myNotes = notes[indexPath.row]
cell.myTextView.text = myNotes.textView
}
}

最佳答案

这里是你可以纠正的方法:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

if indexPath.section == 0 {

//First get your selected cell
if let cell = collectionView.cellForItem(at: indexPath) as? TestViewCollectionViewCell {

//Now get selected cell text here
//update your section two array with new values
//Reload your collection view.


} else {
// Error indexPath is not on screen: this should never happen.
}
}
}

关于swift - 在多个 UICollectionViewCell 之间传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48001320/

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