ios – 在UICollectionView中以编程方式选择项目

ios – 在UICollectionView中以编程方式选择项目,第1张

概述我有一个UICollectionViewController: - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return [self.pageTastes count];}- (UICollectionV 我有一个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

如果需要多次选择,可以多次使用此方法.

总结

以上是内存溢出为你收集整理的ios – 在UICollectionView中以编程方式选择项目全部内容,希望文章能够帮你解决ios – 在UICollectionView中以编程方式选择项目所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1110977.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存