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.
It means
headerViewis not an instance ofThemeHeaderas you expect but an instance ofUICollectionReusableViewwhich does not have atitleproperty.It could be because you might not have set
ThemeHeaderas custom class in the identity inspector on storyboard for this resuable view.