Registering Collection View Header in XCode 5 DP5 using NIB and getting Error

1.8k views Asked by At

I am getting an error when I get the supplementary view for collection view header. I register the supplementary view using the following code

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

There is no errors here. But when I get the view using following code

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    return [self.collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"HomeHeaderView" forIndexPath:indexPath];
}

I get the following error and the app crashes

    2013-08-20 11:00:35.046 MyTime[54845:a0b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 
'invalid nib registered for identifier (HomeHeaderView) - nib must contain exactly one top level object which must be a UICollectionReusableView instance'
    *** First throw call stack:

I have exactly one Collection Reusable View but I have one Object in the Xib as shown in the picture below. I do need this Object as I need to link the Text Field shown in the Header with the Object that is Home View Controller. How can I resolve this issue given my requirement?

enter image description here

1

There are 1 answers

0
mdziadkowiec On

Easy. Make sure you set right Custom Class (subclass of UICollectionReusableView) in XIB.

NOT FOUR FILE'S OWNER but your cell!

Custom Class in XIB