I am trying to hide a UICollectionViewCell in a collection view. Although I am successful when I do
cell.hidden = YES; //or cell.alpha = 0.0;
but after scrolling the cell will reappear. I also tried the following:
UICollectionViewLayoutAttributes *layoutAttr = <get the layout attribute>
I thought it could be because I use the dequeReusable.. method and therefore the cell is reused, but I also tried to hide the cell in the collectionView:cellForItemAtIndexPath: method to no avail. It doesnβt even work here.
Why is this not working? How can I hide a UICollectionViewCell ?
EDIT: Implementation of 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; }
Should this hide all cells? But no, this does not happen.
ios objective-c cocoa-touch uicollectionview uicollectionviewcell
Rakesh
source share