Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionReusableView for section header not working

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.

like image 752
Subash Avatar asked Jan 03 '14 20:01

Subash


People also ask

How to add section header in collectionView swift?

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! }

What is collection reusable view?

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.


1 Answers

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.

like image 165
Yas Tabasam Avatar answered Sep 19 '22 09:09

Yas Tabasam