1

I have a UICollectionViewController which delegates UICollectionViewDataSource and UICollectionViewDelegate. My collection view displays 2 sections with multiple rows of data and works fine.

I have created a Section Header (in IB Attributes Inspector -> Accessories) which then subclasses UICollectionReusableView with the SWOHighScoreHeader class:

@interface SWOHighScoreHeader : UICollectionReusableView
@property (strong, nonatomic) IBOutlet UILabel *hiScoreHead;
@end

I set this class (SWOHighScoreHeader) as the Custom Class for the UICollectionReusableView in IB.

In the UICollectionViewController I use the method:

-(UICollectionReusableView*)collectionView:(UICollectionView*)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{

SWOHighScoreHeader *highScoreHeaderView = nil;

if ([kind isEqual:UICollectionElementKindSectionHeader]) {
    highScoreHeaderView = [collectionView dequeueReusableSupplementaryViewOfKind:kind
                                                             withReuseIdentifier:@"highScoreTableHead"
                                                                    forIndexPath:indexPath];
}

return highScoreHeaderView;
}

The identifier highScoreTableHead is set as the UICollectionReusableView Collection Reusable View Identifier in IB.

At this stage, the section headers display correctly, albeit with the default label text.

My issue comes when I connect the IBOutlet UILabel hiScoreHead property with the outlet in IB. When I do this, the program crashes with:

Unknown class SWOHighScoreHeader in Interface Builder file.

** * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key submitButton.'

I've tried deleting the outlet connection and reconnecting but still nothing. Any ideas where I am going wrong?

Mark__C
  • 825
  • 1
  • 13
  • 24

3 Answers3

0

Add the following property to SWOHighScoreHeader:

@property (weak) IBOutlet UIButton* submitButton;

Or try to find out which object in your storyboard is expecting the submitButton to actually exist.

joeybladb
  • 227
  • 1
  • 10
  • I added the submitButton and connected it in IB in the same way but same problem. >>Or try to find out which object in your storyboard is expecting the submitButton to actually exist.<< How would I do that? – Mark__C Apr 02 '15 at 19:08
  • It's rather arduous, but go to your storyboard, open the Connections inspector and then go through your view hierarchies view by view until you find an orphaned outlet or action targeting submitButton. – joeybladb Apr 02 '15 at 23:05
0

An IBoutlet must always be a weak property, otherwise its container will not be deallocated.

Kujey
  • 1,122
  • 6
  • 17
  • OK, thanks. I have been unsure about this. Have changed to weak but it's not the cause of the problem. – Mark__C Apr 02 '15 at 19:09
0

I solved this by using Tags instead of IBOutlets ie

UILabel *hiScoreHeader = (UILabel *)[highScoreHeaderView viewWithTag:101];
hiScoreHeader.text = @"Header Text";

I'm not sure why the IBOutlets don't work but at least I have a solution.

Mark__C
  • 825
  • 1
  • 13
  • 24