【发布时间】:2014-12-03 08:58:48
【问题描述】:
我有一个带有自定义 UICollectionViewLayout 的 UICollectionView,并希望为每个部分添加多个标题以显示一天中的不同时间。类似于周视图的东西,在我的情况下,时间在左侧垂直,但在顶部和水平方向。
单元格显示良好,但内容很奇怪,看起来单元格被重复使用,屏幕上的 5 个单元格中只有 1 个有内容。其他 4 个标题只有背景颜色,没有内容。
当我滚动时,会出现一些故障,一次只更新一个单元格(有时是 2 个),并且内容可以切换或错位一行。
这是我在控制器中使用的代码 viewDidLoad
[self.epgCollectionView registerClass:[HeaderTimeReusableView class] forSupplementaryViewOfKind:EpgKindTimeRowHeader withReuseIdentifier:HeaderTimeReuseIdentifier];
下面还有相同的控制器:
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
UICollectionReusableView *view;
if (kind == EpgKindTimeRowHeader){
HeaderTimeReusableView *timeRowHeader = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:HeaderTimeReuseIdentifier forIndexPath:indexPath];
timeRowHeader.title.text = [NSString stringWithFormat:@"s%lir%li", (long)indexPath.section, (long)indexPath.row];
view = timeRowHeader;
}
return view;
}
我想我的自定义 UICollectionViewLayout 很好,因为我可以在我想要的地方看到多个标题。
我的问题是:
- 每个部分可以有多个标题吗?
- 如何避免这些标头的重用/回收效应?
- UICollectionViewCells 也使用 dequeue,但我们可以每个部分有多个单元格,那么为什么它不适用于 headers/UICollectionReusableView 呢?
【问题讨论】:
标签: uicollectionview uicollectionviewcell uicollectionviewlayout uicollectionreusableview