【发布时间】:2012-11-01 12:35:23
【问题描述】:
我有一个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 第一次加载时,一些项目会根据CellTasteCollectionView 中的objectId 以编程方式被选中。
我是这样做的:
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
Taste *taste = [self.pageTastes objectAtIndex:indexPath.item];
printf("%s\n", [taste.objectId UTF8String]);
}
当用户点击项目时调用它——这不是我想要的:我希望在 UICollectionView 加载时自动选择项目。
我该怎么做?
【问题讨论】:
标签: ios objective-c uicollectionview