Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are cells deselected programmatically in UICollectionView when allowMultipleSelection is enabled?

I have allowMultipleSelection enabled in a collection view. The cells change to and from their selected states when tapped. All good. However, when I want to reset the entire view to selected state:NO using the code below, the cells appears to be entirely deselected until I then make a new selection, at which point all previously selected cells show their previously selected state.

i.e. despite appearances the collectionview is not updating it's current selection list when I programmatically deselect the cells

- (void)clearCellSelections {    for (LetterCell  *cell in self.collectionView.visibleCells) {         [cell prepareForReuse];     } } 

In custom cell:

- (void)prepareForReuse {     [super prepareForReuse];     [self setSelected:NO]; } 

What am I doing wrong? Is there another way to deselect all cells?

Thanks TBlue for taking a look

like image 811
Steve Avatar asked Jan 21 '13 15:01

Steve


1 Answers

You can iterate over - [UICollectionView indexPathsForSelectedItems]:

for (NSIndexPath *indexPath in [self.collectionView indexPathsForSelectedItems]) {     [self.collectionView deselectItemAtIndexPath:indexPath animated:NO]; } 
like image 170
qorkfiend Avatar answered Sep 21 '22 03:09

qorkfiend