我有mainUICollectionView
个自定义mainUICollectionViewCell
。在此mainUICollectionViewCell
中,nestedUICollectionView
为nestedUILabel
和nestedUICollectionViewCell
。
我尝试加载的数据是名为questions = [Question]()
的变量,其中Question
是自定义类。每个Question
对象都有title
和[string]()
。
以下是我尝试实现的逻辑:
1. mainCollectionView
应根据questions.count
填充
2. nestedLabel.text = question[indexPath.row].tite
3. nestedCollectionView
应根据相应answer
的{{1}}属性填充。
我通过引用question
viewControllers
属性轻松完成了前两个任务。但是,由于我questions
的{{1}}和UICollectionViewDelegate
位于UICollectionViewDataSource
,因此无法获得参考资料。我怎么能实现这第三步呢?
三江源
答案 0 :(得分:1)
你可以尝试
class ViewController : UIViewController {
func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
// pass data only ,this in the viewController
let answers = questions[indexPath.row].answers
cell.answers = answers
//
}
}
&安培;
class mainUICollectionViewCell: UICollectionViewCell , UICollectionViewDelegate , UICollectionViewDataSource {
var answers = [String]()
override func awakeFromNib () {
self.nestedCollectionView.delegate = self
self.nestedCollectionView.dataSource= self
// register the nib / nestedUICollectionViewCell here
}
}
//
在cellForRow
之前的ASKpScoreLog
内return cell
内进行
cell.collectionView.reloadData()