我有一个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时自动选择该项目.
我该如何做?
解决方法
我想你从
UICollectionView Class Reference错过了这个方法:
- (void)selectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UICollectionViewScrollPosition)scrollPosition
如果需要多次选择,可以多次使用此方法.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。