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.
Connecting the Section Header to Data swift in an additional editor pane and Control-drag from the label in the header view over to the file and name the outlet titleLabel. It will add the following code: class FlickrPhotoHeaderView: UICollectionReusableView { @IBOutlet weak var titleLabel: UILabel! }
Reusable views are so named because the collection view places them on a reuse queue rather than deleting them when they are scrolled out of the visible bounds. Such a view can then be retrieved and repurposed for a different set of content.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With