【发布时间】:2014-06-04 17:42:00
【问题描述】:
场景:我想使用 indexPath 检查特定可见 UICollectionViewCells 的选定状态,我在 UICollectionView 参考上为其调用 cellForItemAtIndexPath。
问题:调用 UICollectionView.cellForItemAtIndexPath 总是调用 UICollectionViewDatasource.cellForItemAtIndexPath 返回一个没有选择状态的新单元格。
问题:为什么 UICollectionView.cellForItemAtIndexPath 总是调用 UICollectionViewDatasource.cellForItemAtIndexPath ?
Apple 文档说返回值为“对应索引路径处的单元格对象,如果单元格不可见或 indexPath 超出范围,则返回 nil。”
是我遗漏了什么还是我在数据源中的 cellForItemAtIndexPath 实现不正确?
- (UICollectionViewCell*) collectionView: collView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
SudoCell *cell = [collView dequeueReusableCellWithReuseIdentifier:CELL_ID forIndexPath:indexPath];
[cell setValuesWithSection:indexPath.section item:indexPath.item modelObject:_model];
cell.backgroundColor = [UIColor whiteColor];
return cell;
}
作为当前的解决方法,我将部分和项目值存储为单元格的实例值。循环遍历所有可见单元格以查找与部分和项目值匹配的单元格并检查可见状态。当细胞数量很大时,这变得很乏味。
请指教。
【问题讨论】:
标签: ios uicollectionview