ios – 隐藏UICollectionViewCell

我试图在集合视图中隐藏UICollectionViewCell.虽然我做的时候我很成功
cell.hidden = YES; //or cell.alpha = 0.0;

但滚动后,单元格再次出现.我也尝试了以下内容

UICollectionViewLayoutAttributes *layoutAttr = <get the layout attribute>//I'm succesfull here
layout.hidden = YES;
[cell applyLayoutAttributes:layoutAttr];

我认为这可能是因为我正在使用dequeReusable ..方法,因此该单元格正被重新使用,但是
我也试图隐藏collectionView:cellForItemAtIndexPath:方法中的单元格无济于事.在这里它似乎甚至没有工作.

为什么这不起作用?如何隐藏UICollectionViewCell?

编辑:包含collectionView的实现:cellForItemAtIndexPath ::

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    static Nsstring *identifier = @"Cell";

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    cell.layer.cornerRadius  = 12.0f;
    cell.backgroundColor = [UIColor colorWithRed:0.830 green:0.899 blue:1.000 alpha:1.000];

    cell.selectedBackgroundView = [[UIView alloc]initWithFrame:cell.frame];
    cell.selectedBackgroundView.backgroundColor = [UIColor lightTextColor];;
    cell.layer.borderColor = [UIColor blackColor].CGColor;
    cell.layer.borderWidth = 2.0f;
    cell.hidden = YES;
    UILabel *lbl = (UILabel *)[cell viewWithTag:10];
    NSArray *interarray = numberArray[indexPath.section];
    [lbl setText:[interarray[indexPath.row] stringValue]];

    return cell;



}

这应该隐藏所有细胞吗?但不,不会发生.

解决方法

由于隐藏单元格本身似乎不起作用,您可以使用与集合视图的背景颜色相同的颜色向单元格添加子视图,也可以隐藏单元格的内容视图,该视图可以正常工作:
cell.contentView.hidden = YES;
cell.backgroundColor = self.collectionView.backgroundColor;

只有在为单元格设置背景颜色时才需要第二行.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...