我必须根据我的 api 响应隐藏 uicollectionview 的一些单元格。
我根据我的 json 响应值在 collectionview 的 sizeForItemAtIndexPath 方法中将单元格大小设置为零。
但即使将大小设置为零后,位于第 0 个索引的单元格始终可见。
我无法过滤掉并从数组中删除数据。我需要这些数据进行一些操作。
我的 UICollectionView 数据源方法。
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 5
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! testCell
cell.lblTest.text = "\(indexPath.item)"
return cell
}
我的流程布局委托方法。
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if (indexPath.section == 0 && indexPath.item == 0) || (indexPath.section == 1 && indexPath.item == 0){
return CGSize(width: 0, height: 0)
}
return CGSize(width: 50, height: 50)
}