【发布时间】:2017-12-28 03:40:20
【问题描述】:
我有一个包含 2 个不同部分的集合视图。我想点击其中一个部分中的一个单元格并将该单元格中的文本传递给文本视图,该视图位于其自己部分的单独单元格中。
这是我到目前为止尝试过的,但什么也没发生。我正在尝试将笔记数据发送到另一个单元格。点击单元格时我可以打印数据。
已更新:这是带有文本视图的单元格,我要将选定的单元格数据传递到该单元格。
// 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
}
}
【问题讨论】:
-
没有人知道音符是什么。
-
@El Tomato,感谢您的回复。 notes 是一个字符串数组,我用它来填充集合视图。
-
@IamWayne 你应该使用
cellForItem而不是dequeueReusableCell。 -
@trungduc 感谢您的回复,我是 swift 和收藏视图的新手。但我使用 cellForItem 在集合视图单元格中显示数据。只是不知道如何将数据从一个单元格传递到另一个单元格的单独部分。
-
你应该使用你想要放入文本的单元格的 indexPath 来 dequeueReusableCell,而不是你点击的单元格。
标签: swift swift3 uicollectionview uicollectionviewcell