小编d_C*_*CFO的帖子

如何确定当前可见的UICollectionView单元格的indexPath

我想显示一些特定于单元格的文本,但我无法从集合视图中解除可见单元格.

最有帮助的是这些:

如何从UICollectionViewCell访问UICollectionView中Cell的indexPath

检测iOS UICollectionCell何时离开屏幕

较低的集合视图(self addSubview)包含可能的项目.较高的一个(self addSubview)包含较低的选项.用户按下按钮(再次自我addSubview),下部视图滚动到遗忘,上部视图展开,以便一个单元格填满屏幕.所有的阵列构建和显示都很好.没有*.nibs.

什么是行不通的是确定应用程序向用户呈现的单元格.

尝试#1:首先我尝试将UILabel与普通操作并行填充.按下按钮和cellForItemAtIndexPath:

if (cv.tag == UPPER_CV_TAG) {
    UICollectionViewLayoutAttributes *itemAttributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
    NSIndexPath *tempIndexPath;
tempIndexPath = itemAttributes.indexPath;
NSLog(@"cellForItem indexPath %@",indexPath);
NSLog(@"layout indexPath %@",tempIndexPath);
}
Run Code Online (Sandbox Code Playgroud)

按照你的期望回应:

cellForItem indexPath <blah blah> 2 indexes [0, 0]
layout indexPath < > 2 indexes [0, 0]

cellForItem indexPath < > 2 indexes [0, 1]
layout indexPath < > 2 indexes [0, 1]

cellForItem indexPath < > 2 indexes [0, 2]
layout indexPath < > 2 indexes [0, …
Run Code Online (Sandbox Code Playgroud)

objective-c uicollectionview

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

objective-c ×1

uicollectionview ×1