Мне нужно скрыть некоторые ячейки uicollectionview, основываясь на моем ответе API.
Я устанавливаю нулевой размер ячейки в методе sizeForItemAtIndexPath коллекции viewview на основе значения моего ответа json.
, нодаже после установки нулевого размера ячейка с нулевым индексом всегда видна.
Я не могу отфильтровать и удалить данные из массива.мне нужны эти данные для некоторых операций.
мой метод источника данных 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)
}
ожидаемый результат - ячейка на 0-м местеИндекс в 0 и 1 разделе скрыт, но он все еще отображается.![enter image description here](https://i.stack.imgur.com/RbFSa.png)