Idan Yehuda
Idan Yehuda

Reputation: 560

How to change UICollectionViewCell selection of a non-visible cell?

Is there any way to change the 'selected' member of a UICollectionViewCell that is not in the "visibleCells"? (beside saving the Cell object of the last selected cell...)

Upvotes: 0

Views: 575

Answers (1)

streem
streem

Reputation: 9144

In order to change the selected status of an item you should call the method selectItemAtIndexPath: Items can be reused, so if you call the setSelected method of UICollectionViewCell, it might not select the right item.

[self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];

If you want to deselect it you have this method:

[self.collectionView deselectItemAtIndexPath:indexPath animated:NO];

Upvotes: 1

Related Questions