1
2つの異なるセクションを持つコレクションビューがあります。セクションの1つでセルをタップして、そのセルのテキストをテキストビューに渡したいとします。テキストビューは、それ自身のセクションの別のセルにあります。複数のUICollectionViewCell間でデータを渡す
これはこれまで私が試したことですが、何も起こりませんでした。ノートデータを別のセルに送信しようとしています。私は、セルがタップされたときにデータを印刷することができます。
:これは、選択したセルデータを渡すテキストビューのセルです。ここで
// 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
}
}
誰にも指摘されて何を知っていません。 –
@エル・トマト、ご返信ありがとうございます。 notesは文字列の配列で、コレクションビューにデータを格納するために使用しています。 –
@IamWayne 'dequeueReusableCell'の代わりに' cellForItem'を使うべきです。 – trungduc