1

我有一个自定义的UICollectionViewLayout一个UICollectionView,并希望每节添加多个标题来显示不同小时不间断的。同样的事情也给了左侧的垂直小时,但在顶部和水平为我的情况下,周视图。uicollectionview自定义布局和多个头

细胞显示良好,但内容是奇怪,它看起来像细胞被重新使用和5只有1是在屏幕上有一个内容。其他4个标题只有背景颜色,没有内容。

在i滚动,有一次一些毛刺和更新只有一个小区(有时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好的,因为我可以看到多标题在我想要的地方。

我的问题是:

  1. 是否有可能让每个节多个标头?
  2. 如何避免这些头文件的重用/回收的效果呢?
  3. 的UICollectionViewCells使用离队太多,但我们可以有每节多个单元格,为何还没有页眉/ UICollectionReusableView工作?

回答

0

一如往常,这是当我发布,我找到答案的问题...

这是我的可重复使用的视图好的代码:

- (id)initWithFrame:(CGRect)frame 
{ 
NSLog(@"HeaderTimeReusableView.h initWithFrame"); 
self = [super initWithFrame:frame]; 
if (self) { 
    self.backgroundColor = [UIColor greenColor]; 

    self.title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60*3, 30)]; 
    self.title.backgroundColor = [UIColor redColor]; 
    self.title.font = [UIFont systemFontOfSize:12.0]; 
    self.title.text = @"3"; 
    [self addSubview:self.title]; 

} 
return self; 

}

我以前曾这样分配标签框架:

self.title.frame = frame; 

由于某种原因,帧值不是我所期望的。硬编码的,它工作正常。