我有多维数组,例如如下所示,如何在表视图/已查看cel上传递我的集合视图数组?
let array = [["abc " , " bce "] , ["a "] , ["abc " , " abce " , " a "] , []]
我想要第一个单元格的第一个数组对象,第二个单元格的第二个数组对象并且连续。
答案 0 :(得分:2)
你可以这样实现
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]
}
}