CollectionView cell with Highlight

0

I have a collectionView with several cells, when I click one I need it to look like it has been pressed with a color or animation.

For this I use:

  • (void) collectionView: (UICollectionView *) collectionView didHighlightItemAtIndexPath: (NSIndexPath *) indexPath { MiCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier: @ "myCells" forIndexPath: indexPath]; cell.vHighlight.backgroundColor = [UIColor colorWithRed: 255 / 255.0 green: 255 / 255.0 blue: 153 / 255.0 alpha: 1]; }
  • (void) collectionView: (UICollectionView *) collectionView didUnhighlightItemAtIndexPath: (NSIndexPath *) indexPath { MiCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier: @ "myCells" forIndexPath: indexPath]; cell.vHighlight.backgroundColor = [UIColor clearColor]; }

When I press the cell I have verified that it goes to the corresponding method but when I change the background color of the cell it is not reflected in the view.

    
asked by Popularfan 17.01.2018 в 09:32
source

1 answer

1

I would try to use func cellForItem(at: IndexPath) to make sure that the cell that is actually showing up for that indexPath is being recovered.

It could happen that dequeueReusableCellWithReuseIdentifier: would return a cell that at that moment is not being displayed and, therefore, it is considered that it can be reused at that moment for that indexPath.

I hope I have been helpful.

    
answered by 17.01.2018 / 09:49
source