コレクションビューでテーブルビューセルのデータを使用します。それらは同じコントローラ内にあります。どうやってやるの ?これを試すと、デリゲートは無限になり、何も起こりません.Notmind CellForRowAtIndexPath、numberOfRowsInSectionメソッド。デリゲートとプロトコルについてはどうすれば修正できますか?
protocol DataDelegate {
func dataInfo(survey:Survey)
}
import UIKit
class SurveyViewControllerLeftTableView: UITableView,UITableViewDataSource,UITableViewDelegate {
var survey = [Survey]()
var myDelegate : DataDelegate?
override func awakeFromNib() {
self.dataSource=self
self.delegate=self
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
myDelegate?.dataInfo(survey[(indexPathForSelectedRow?.row)!])
}
}
import UIKit
class BottomCollectionView: UICollectionView,UICollectionViewDataSource,UICollectionViewDelegate,DataDelegate {
var surveyBottomCollection = [Survey]()
override func awakeFromNib() {
super.awakeFromNib()
self.delegate = self
self.dataSource = self
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return surveyBottomCollection.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell : BottomCollectionViewCell = dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! BottomCollectionViewCell
cell.surveyQuestionNumberLabel.text = surveyBottomCollection[indexPath.row].questionNumber
cell.surveyQuestionDescriptionLabel.text = surveyBottomCollection[indexPath.row].questionDescription
return cell
}
func dataInfo(survey: Survey) {
print(survey.questionDescription)
surveyBottomCollection.append(survey)
self.reloadData()
}
私はここで、 'CollectionView' Cellを' UITableView'に再利用する必要があることを理解していますが、上記のようなコードで直接動作するとは思いません。 'UITableView' Cellを作成し、Collectionビューからそのセルに必要なデータを割り当てる必要があります。 – CodeChanger
私はすでにUITableView Cellを作成しましたが、どのように割り当てることができますか?簡単な例を教えていただけますか?よくわかりません。 –
私にあなたに説明させてください、1つのコントローラにビューとコレクションとテーブルがあります。私はコレクションビューのセルのデータを送信するために、テーブルビューのセル内のすべての情報をクリックするとします。 –