Reputation: 101
I have multidimensional array for example like following, how can I pass the array of my collection view on / of a table views / viewed cel ?
let array = [["abc " , " bce "] , ["a "] , ["abc " , " abce " , " a "] , []]
I want first array object of first cell, second array object of second cell and continuous.
Upvotes: 3
Views: 1409
Reputation: 3310
You can implement like this way
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]
}
}
Upvotes: 2