例如,我有如下多维数组,如何将我的 Collection View 的数组传递到/ TableView /查看的 cel 上?
let array = [["abc " , " bce "] , ["a "] , ["abc " , " abce " , " a "] , []]
我想要第一个单元格的第一个数组对象,第二个单元格的第二个数组对象并且是连续的。
最佳答案
你可以这样实现
extension YourViewController : UICollectionViewDelegate,UICollectionViewDataSource {
func numberOfSections(in collectionView: UICollectionView) -> Int {
return array.count
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return array[section].count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionCell", for: indexPath)
let string = array[indexPath.section][indexPath.item]
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let selectedString = array[indexPath.section][indexPath.item]
}
}
关于ios - 如何在 tableview 单元格内的 Collection View 中传递多维数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47655380/