Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top