5

I created a UICollectionReusuable view for UICollecton view section header. I use the following code the implement the header view.

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
ThemeHeader *headerView = [[ThemeHeader alloc] init];
headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
                                                                 withReuseIdentifier:@"header"
                                                                        forIndexPath:indexPath];
NSString *title = @"Title for the header";
headerView.title.text = title;
return headerView;

}

It crashes giving me the following error:

-[UICollectionReusableView title]: unrecognized selector sent to instance 0xac846a0'

My ThemeHeader class looks like this

@interface ThemeHeader : UICollectionReusableView
@property (strong, nonatomic) IBOutlet UILabel *title;

@end

I appreciate your help in advance.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Subash
  • 1,002
  • 13
  • 26
  • Why are you creating headerView and then reinitialising with dequequed View? – ldindu Jan 03 '14 at 21:02
  • Is your title IBOutlet connected properly to its respective UILabel on nib? – ldindu Jan 03 '14 at 21:03
  • 1
    Did you register class with a following method registerClass:forSupplementaryViewOfKind: withReuseIdentifier: for your supplementary view? – ldindu Jan 03 '14 at 21:26

1 Answers1

8

It means headerView is not an instance of ThemeHeader as you expect but an instance of UICollectionReusableView which does not have a title property.

It could be because you might not have set ThemeHeader as custom class in the identity inspector on storyboard for this resuable view.

Yas Tabasam
  • 10,517
  • 9
  • 48
  • 53