【问题标题】:Can we show two sections with fixed height CollectionView in swift?我们可以在 swift 中显示两个固定高度的 CollectionView 部分吗?
【发布时间】:2021-08-23 17:06:15
【问题描述】:

我给出了如下的collectionview约束

top = leading = trailing = 10, height = 130

collectionview 单元格代码

override func viewDidLoad() {
    super.viewDidLoad()
    let layout = UICollectionViewFlowLayout()
    layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
    layout.scrollDirection = .horizontal
    let width = UIScreen.main.bounds.width/4.1
    
    layout.itemSize = CGSize(width: width, height: 100)
    self.filesCollectionView.collectionViewLayout = layout
}

部分和行的代码:使用此代码,两个数组图像都显示在一条水平线上

如何在一个部分显示oldArray 图像,在另一部分显示newArray 图像

func numberOfSections(in collectionView: UICollectionView) -> Int {
    
    if isEdit{
        return oldArray.isEmpty ? 1 : 2
    }
    else{
        return 1
    }
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    
    if isEdit{
        if section == 0{
            return  newArray.count
        }
        else{
            return  self.oldArray.count
        }
    }
    else{
        return  self.newArray.count
    }
    return 0
    
}

【问题讨论】:

    标签: swift uicollectionview sections


    【解决方案1】:

    似乎isEdittrue,或者数组在某处混合在一起。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-19
      • 1970-01-01
      • 2017-01-11
      • 2022-01-12
      相关资源
      最近更新 更多