2017-12-28 34 views
1

2 개의 다른 섹션이있는 콜렉션 뷰가 있습니다. 섹션 중 하나에서 셀을 탭하여 해당 셀의 텍스트를 자체 섹션의 별도 셀에있는 텍스트보기로 전달하고 싶습니다.여러 UICollectionViewCell간에 데이터 전달하기

이것은 지금까지 시도했지만 아무 일도 없었습니다. 메모 데이터를 다른 셀로 보내려고합니다. 셀을 두드리면 데이터를 인쇄 할 수 있습니다.

업데이트 됨 : 선택한 셀 데이터를 전달하려는 텍스트보기가있는 셀입니다.

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. 
     } 
    } 
} 
+0

아무도 짝수 노트 것을 알고 : 여기

// 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 } } 

+0

@ El Tomato, 답장을 보내 주셔서 감사합니다. notes는 컬렉션 뷰를 채우는 데 사용중인 문자열 배열입니다. –

+0

@IamWayne'dequeueReusableCell' 대신'cellForItem'을 사용해야합니다. – trungduc

답변

1

는 당신이를 해결할 수있는 방법입니다.
+0

귀하의 솔루션으로 내 문제가 해결됩니다. 고마워요! –