嵌套CollectionView读取MultiDimensionalArrray以填充单元格

时间:2017-01-26 01:49:12

标签: arrays swift uicollectionview

我在另一个集合视图中有一个集合视图。我可以让内部视图用静态数据数组填充其单元格(因此每个外部集合视图单元格包含相同数量的内部单元格)

外-A-7-内部细胞可见 外部B - 7内部细胞可见

enter image description here

现在我试图让每个外部单元格填充来自多维数组的数据。

阵列的打印在控制台中显示以下内容。

[[ParseStarterProject_Swift.CollectionStruct(name: "pk000-01", description: “This is some text.”, title: "Session 1", image: <PFFile: 0x60000045a790>, id: "WCzjfdJgox"), ParseStarterProject_Swift.CollectionStruct(name: "pk000-02", description: “This is some more text.”, title: "session 2", image: <PFFile: 0x608000447d40>, id: "0yth6YSxbe")]
[ParseStarterProject_Swift.CollectionStruct(name: "pk010-01", description: "Im just testing stuff", title: "Session 1", image: <PFFile: 0x600000454850>, id: "SQYvJTvJwE"), ParseStarterProject_Swift.CollectionStruct(name: "pk010-02", description: "This is some more text about nothing", title: "Session 2", image: <PFFile: 0x60000045b540>, id: "0z6rw6gPVp")]
[ParseStarterProject_Swift.CollectionStruct(name: "pk020-01", description: "Session 1", title: "Session 1", image: <PFFile: 0x608000448910>, id: "vGIjK3jEjc")]]

所以在cellForItemAt函数中,我想只显示第一个单元格中数组第一项的项目。 (橙色单元格中数组第1行的项目)。

这是我的cellForItemAt函数:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {


    if collectionView == self.outerCollectionView {
        let outerCell: OuterCollectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifierOuter, for: indexPath) as! OuterCollectionCell

        outerCell.labelCell.text = self.packArray[indexPath.item].title
        outerCell.layer.cornerRadius = 10

        let temp = myColorArray[indexPath.item].color
        if let hexValue = UInt(String(temp.characters.suffix(6)), radix: 16) {
            outerCell.contentView.backgroundColor = GeneralFunctions.UIColorFromHEX(hexValue: hexValue)

        }

        return outerCell

    } else {

        let innerCell: InnerCollectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifierInner, for: indexPath) as! InnerCollectionCell

            //innerCell.imageCell.file = GlobalParentArray.sharedInstance.globalParentArray[collectionView.tag][indexPath.item].image
            //GlobalParentArray.sharedInstance.globalParentArray[indexPath.item][indexPath.item].image

        //this just returns 7 cells in each outer cell
        //innerCell.imageCell.file = self.partArray[indexPath.item].image
        innerCell.imageCell.loadInBackground()
        innerCell.imageCell.layer.masksToBounds = true


        return innerCell
    }


}

这就是我想象中实现这一目标的方式,但似乎无法显示任何内容。

//innerCell.imageCell.file = GlobalParentArray.sharedInstance.globalParentArray[collectionView.tag][indexPath.item].image

----编辑-----

所以多维数组中的一个数组是空的,导致它没有填充任何内容。

innerCell.imageCell.file = GlobalParentArray.sharedInstance.globalParentArray[collectionView.tag][indexPath.item].image

现在生成一个结果,但只显示索引0 ??

的项目

enter image description here

当我打印时   打印(GlobalParentArray.sharedInstance.globalParentArray [collectionView.tag] .Count之间)`

我得到0然后紧接着是数组中实际的元素数。

INDEX::::::0
INDEX::::::7

0 个答案:

没有答案