我有一个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;
}
有用。我有这个viewDidLoad
,允许用户选择多个项目:
[self.collectionView setAllowsMultipleSelection:YES];
我想要的是,第一次加载 CollectionView 时,一些项目会根据它们的objectId
in 以编程方式被选中CellTasteCollectionView
。
以下是我的做法:
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
Taste *taste = [self.pageTastes objectAtIndex:indexPath.item];
printf("%s\n", [taste.objectId UTF8String]);
}
当用户单击项目时调用它 - 这不是我想要的:我希望在UICollectionView
加载时自动选择项目。
我该怎么做呢?