实施补充标题视图时出现以下错误
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'no UICollectionViewLayoutAttributes instance for -layoutAttributesForSupplementaryElementOfKind: HeaderView at path <NSIndexPath: 0x9e82a40> {length = 2, path = 0 - 0}'
这是创建标题视图的代码
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
static NSString * headerIdentifier = @"HeaderView";
UICollectionReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:headerIdentifier withReuseIdentifier:UICollectionElementKindSectionHeader forIndexPath:indexPath];
return header;
}
该错误发生在 dequeueReusableSupplementaryViewOfKind 方法中。
我在 Collection View Controller 的 initWithCoder 中添加了这两行
UINib *headerNib = [UINib nibWithNibName:@"MTCollectionHeaderView" bundle:nil];
[self.collectionView registerNib:headerNib forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];
所以它确实有对 UI 元素的引用。我无论如何都找不到在标题上设置布局。
我尝试将其添加到同一个集合视图控制器中,但它从未命中此代码,因为我通过在其中放置调试器确认
- (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
return [self.collectionViewLayout layoutAttributesForDecorationViewOfKind:kind atIndexPath:indexPath];
}
有没有人看到这个问题,他们是如何解决的。我也在使用 XCode 5 Developer Preview 5 并为 iOS7 开发