嵌套的CollectionView单元未出现

时间:2018-09-27 08:11:36

标签: ios swift uicollectionview

我将collectionView嵌套在collectionView Cell中,如下所示: enter image description here

在第一个collectionView Cell里面,我放了这段代码:

class CaseCellView: UICollectionViewCell, UICollectionViewDelegate, UICollectionViewDataSource {
    @IBOutlet weak var lblHeader: UILabel!
    @IBOutlet weak var collectionViewItemList: UICollectionView!
    var sellingArray = ["1", "2", "3", "4", "5"]

    override func awakeFromNib(){
        super.awakeFromNib()
        let flowLayout = UICollectionViewFlowLayout()
        flowLayout.scrollDirection = .horizontal
        flowLayout.itemSize = CGSize(width: collectionViewItemList.frame.width, height: collectionViewItemList.frame.width)
        flowLayout.minimumLineSpacing = 5.0
        flowLayout.minimumInteritemSpacing = 5.0
        self.collectionViewItemList.collectionViewLayout = flowLayout
        self.collectionViewItemList?.delegate = self
        self.collectionViewItemList?.dataSource = self
        self.collectionViewItemList.reloadData()
    }

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.sellingArray.count
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: collectionViewItemList.frame.width, height: collectionViewItemList.frame.width)
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsetsMake(0, 0, 0, 0)
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell1 = collectionView.dequeueReusableCell(withReuseIdentifier: "caseListCell", for: indexPath)as! CaseListCellView
        cell1.lblItemList.text = self.sellingArray[indexPath.item]
        cell1.lblItemList.textColor = .white
        cell1.backgroundColor = UIColor.blue

        return cell1

    }
}

class CaseListCellView: UICollectionViewCell {
    @IBOutlet weak var lblItemList: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
    }
}

但是当我运行时,嵌套的collectionView结果没有出现在第一个collectionView中,它只是显示第一个collectionView单元格中的第一个lblHeader。

如何更正我的代码以显示嵌套的collectionView单元格?

0 个答案:

没有答案