ios - 如何在 tableview 单元格内的 Collection View 中传递多维数组?

标签 ios arrays swift object

例如,我有如下多维数组,如何将我的 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/

相关文章:

C - 将指针分配给数组?基于四个例子

javascript - 为什么 reduce 函数输出数组中的项目数?

swift - 展示另一个 View Controller

ios - 为什么不将工作从 NSData 转换为 String? swift

iphone - Xcode 配置文件问题

ios - Swift 中不显示警报 View ?

ios - Popover 覆盖整个屏幕 iOS

ios - 原始类型的枚举不能有带参数的案例

c++ - 将 C++ 字节数组转换为 C 字符串

swift - 从我的 Xcode 项目 Swift 中删除 FontAwesome