【发布时间】:2018-08-27 07:48:34
【问题描述】:
我必须根据我的 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)
}
【问题讨论】:
-
我仍然会使用过滤器方法,复制该数组,在需要时使用过滤器并在需要时使用完整的,因为您似乎需要读取“隐藏”值。另外,
sizeForItemAt是否被调用? -
是的过滤器数组也是一个选项,但我想使用隐藏的值。所以如果我过滤数组,我将不得不重写我当前的其他数组操作的整个逻辑
标签: ios swift uicollectionview uicollectionviewflowlayout