Presumably, you're loading the list of selected category names before any cells are displayed, such as in viewDidLoad
. In that case, you would just need to add some logic to cellForRowAtIndexPath
to select cells who's category name is in selectedCategories
. It might look something like this:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = ...;
NSString *category = self.categoryNames[indexPath.item];
if ([self.selectedCategories containsObject:category] && !cell.selected) {
[self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
// There seems to be a bug in UICollectionView such that the previous
// statement doesn't trigger the cell's selected view to be displayed.
// Adding the following statement fixes the issue. Keeping the above
// statement because it is important when allowsMultipleSelection is NO.
cell.selected = YES;
}
}