我有一个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;
}
Run Code Online (Sandbox Code Playgroud)
有用.我有这个viewDidLoad,允许用户选择多个项目:
[self.collectionView setAllowsMultipleSelection:YES];
Run Code Online (Sandbox Code Playgroud)
我想什么都有,就是第一次的CollectionView负荷,某些项目编程选择的基础上,他们objectId在CellTasteCollectionView.
这是我如何做到这一点:
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
Taste *taste = [self.pageTastes objectAtIndex:indexPath.item];
printf("%s\n", [taste.objectId UTF8String]);
}
Run Code Online (Sandbox Code Playgroud)
当用户点击项目时调用它 - 这不是我想要的:我希望在UICollectionView加载时自动选择项目.
我该怎么做呢?