Error when adding Supplementary Header View to UICollectionView

I am getting the following error implementing the supplementary Header View

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'no UICollectionViewLayoutAttributes instance for -layoutAttributesForSupplementaryElementOfKind: HeaderView at path <NSIndexPath: 0x9e82a40> {length = 2, path = 0 - 0}'

This is the code that is creating header view

- (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;
}

The error happens in dequeueReusableSupplementaryViewOfKind method.

I have added these two lines in my initWithCoder of the Collection View Controller

UINib *headerNib = [UINib nibWithNibName:@"MTCollectionHeaderView" bundle:nil];
[self.collectionView registerNib:headerNib forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];

so it does have a reference to the UI element. I cannot find anyway to set the layout on the header.

I tried adding this to the same Collection View Controller but it never hit this code as I confirmed by putting a debugger there

- (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    return [self.collectionViewLayout layoutAttributesForDecorationViewOfKind:kind atIndexPath:indexPath];
}

Has anyone seen this issue and how did they resolve it. Also I am using XCode 5 Developer Preview 5 and developing for iOS7

Answers


I believe you are passing the headerIdentifier for the kind of supplementary view and the kind constant for the header identifier. Try switching them as shown in this line of code in your collectionView:viewForSupplementaryElementOfKind:atIndexPath: method:

UICollectionReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerIdentifier forIndexPath:indexPath];

I also do not think you need your implementation of layoutAttributesForSupplementaryElementOfKind:atIndexPath:, swap the above line of code in and see if it works.


Need Your Help

Joining sql views in oracle sql

sql oracle join views union-all

How can I join views using sql? I'm using Oracle at the moment?

Can iptables allow DNS queries only for a certain domain name?

linux dns iptables

I have iptables blocking all UDP traffic at the moment, however I want to allow only certain DNS queries to get through.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.