I have a UICollectionViewController
:
- (NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section {
return [self.pageTastes count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CellTasteCollectionView *cell =
[collectionView dequeueReusableCellWithReuseIdentifier:@"Cell"
forIndexPath:indexPath];
Taste *taste = [self.pageTastes objectAtIndex:indexPath.item];
[[cell imageView] setImage:taste.image];
[cell setObjectId:taste.objectId];
return cell;
}
It works. I have this in viewDidLoad
, allowing the user to choose multiple items:
[self.collectionView setAllowsMultipleSelection:YES];
What I want to have, is that the first time the CollectionView loads, some items get selected programmatically, based on their objectId
in CellTasteCollectionView
.
Here's how I'm doing this:
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
Taste *taste = [self.pageTastes objectAtIndex:indexPath.item];
printf("%s
", [taste.objectId UTF8String]);
}
It's called when the user clicks on the item -- this is not what I want: I want the item to be selected automatically when UICollectionView
loads.
How do I do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…