0
我有這樣的方法來供應UICollectionView部分簡單的啞頭:的iOS:UICollectionView實施viewForSupplementaryElementOfKind轟炸
- (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
這是怎麼回事這裏錯了嗎?
它只是一個'UIView'我在代碼中創建註冊類/筆尖?用'UILabel'這是一個愚蠢的簡單視圖。 – Wells
只是子類UIView和註冊。 doc鏈接:https://developer.apple.com/library/ios/documentation/uikit/reference/UICollectionView_class/Reference/Reference.html#//apple_ref/occ/instm/UICollectionView/registerClass:forSupplementaryViewOfKind:withReuseIdentifier: – sage444