Here's the answer.
Call selectItemAtIndexPath instead of [self.myCollectionView cellForItemAtIndexPath:indexPath] setSelected:YES];
Code example:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0] ; [self.collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone]; if ([[self.collectionView cellForItemAtIndexPath:indexPath] isSelected]) { NSLog(@"selected count %i",[self.collectionView indexPathsForSelectedItems].count); }
audio output
selected count 1
source share