我有这个方法为UICollectionView部分提供一个简单的哑页头:
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionReusableView *header = nil;
NSString *sectionTitle;
switch (indexPath.section) {
case 0:
sectionTitle = @"One";
break;
case 1:
sectionTitle = @"Two";
break;
case 2:
sectionTitle = @"Thre";
break;
case 3:
sectionTitle = @"Four";
break;
}
if (kind == UICollectionElementKindSectionHeader) {
header = [collectionView dequeueReusableSupplementaryViewOfKind:kind
withReuseIdentifier:@"headerView"
forIndexPath:indexPath];
UILabel *sectionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
sectionLabel.text = sectionTitle;
[self.rosterCollectionView addSubview:sectionLabel];
}
return header;
}
它在dequeueReusableSupplementaryViewOfKind
电话上炸弹:
*** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:], /SourceCache/UIKit/UIKit-2903.23/UICollectionView.m:3117
这里出了什么问题?
答案 0 :(得分:0)
在使用dequeue方法之前,您应该使用registerNib:forSupplementaryViewOfKind:withReuseIdentifier:
或registerClass:forSupplementaryViewOfKind:withReuseIdentifier:
注册您的班级/笔尖