我有一个带有自定义 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 也使用出队,但我们可以每个部分有多个单元格,那么为什么它不适用于 headers/UICollectionReusableView 呢?