3
가 여기에 관련 코드의 작업을 가져올 수 없습니다 :은 UICollectionView 헤더
컨트롤러 : 여기
- (instancetype)init {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(106.0, 106.0);
layout.minimumInteritemSpacing = 1.0;
layout.minimumLineSpacing = 1.0;
layout.headerReferenceSize = CGSizeMake(320.0, 44.0);
return (self = [super initWithCollectionViewLayout:layout]);
}
- (void)viewDidLoad {
[super viewDidLoad];
// some setup
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.collectionView registerClass:[ITPhotosHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
UICollectionReusableView *reusableView;
if (kind == UICollectionElementKindSectionHeader) {
ITPhotosHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
withReuseIdentifier:@"header" forIndexPath:indexPath];
headerView = [[ITPhotosHeaderView alloc] initWithFrame:CGRectMake(0, 0, 320.0, 44.0)];
reusableView = headerView;
}
return reusableView;
}
입니다 오류가 나는 얻을 :
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'the view returned from -collectionView:viewForSupplementaryElementOfKind:atIndexPath (UICollectionElementKindSectionHeader,<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}) was not retrieved by calling -dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath: or is nil (<ITPhotosHeaderView: 0x1781b9de0; baseClass = UICollectionReusableView; frame = (0 0; 320 44); layer = <CALayer: 0x17802f980>>)
내가 디버깅하고 반환되지 않았 음을 확인했다 무. 따라서 registerClass
부분이 올바르게 작동하지 않는 것 같습니다. 나는 어떤 의견을 주셔서 감사하겠습니다. 감사.
네가 맞아. 그건 바보 같았 어. 고맙습니다. – isal
하지만 그 특별한 예외는 본 적이 없으므로 배울 것이 재미있었습니다! 따라서 질문은 좋은 질문이었습니다. 결국 다른 누군가가 같은 예외를 겪을 수도 있습니다. – matt