objective-c - 如何从代码中选择 UICollectionView 的项目/单元格

标签 objective-c ios ipad uicollectionview uicollectionviewcell

我在我的应用程序中实现了一个 UICollectionView。我的问题是我需要选择(就像用户点击它一样)一个单元格以编程方式。 方法:

- (void)selectItemAtIndexPath:(NSIndexPath *)indexPath 
                     animated:(BOOL)animated 
               scrollPosition:(UICollectionViewScrollPosition)scrollPosition

UICollectionView 类的一部分不是我需要调用的,因为此方法不调用:

- (void)collectionView:(UICollectionView *)collectionView 
        didSelectItemAtIndexPath:(NSIndexPath *)indexPath

它只是将单元格的selected 属性设置为YES

最佳答案

是的,这是正确的行为。 [selectItemAtIndexPath:animated:scrollPosition:] 的文档 says :

This method does not cause any selection-related delegate methods to be called.

关于objective-c - 如何从代码中选择 UICollectionView 的项目/单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13859736/

相关文章:

ios - 在视频上添加 GPUImagePicture

iphone - 是否可以从我的应用程序启动(将用户重定向到)iPhone 的 native 照片库应用程序,

ios - 使用 CGAffineTransform 将 UILabel 字体大小减小到精确点

ios - Spritekit : how to make game screen view move upwards as node "jumps" along the y axis?

ios - 使用 Google Drive SDK 的 disallowed_useragent

objective-c - 核心动画+核心音频+ sleep 未按预期顺序进行

ios - asyncAfter 不延迟指定时间的第一次执行

iphone - 如何正确命名通用应用程序的所有启动图像?

css - 如何使用 SASS 或 CSS3 将 !important 放在所有 CSS 属性中?

ios - 如果显示图片 A,则必须输入文本 A,否则 LABEL 表示错误