我试图在集合视图中隐藏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; }
这应该隐藏所有细胞吗?但不,不会发生.