我有一个UICollectionViewController
:选择项目以编程方式UICollectionView
- (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负荷,某些项目编程选择,根据他们在CellTasteCollectionView
objectId
。
以下是我正在做的:
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
Taste *taste = [self.pageTastes objectAtIndex:indexPath.item];
printf("%s\n", [taste.objectId UTF8String]);
}
当用户点击该项目这就是所谓的 - 这是不是我想要的:我要当UICollectionView
负载自动选择的项目。
我该怎么做?
感谢您的帮助。 :) – Ali
请注意,以编程方式调用此方法将不会触发collectionView:didSelectItemAtIndexPath :. – Boon