My app is crashing because of
[UICollectionViewFlowLayout collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance.
This is because my delegate methods are inside my UICollectionReusableView
which is not a view controller. How can I embed a UICollectionView inside of a UICollectionViewSectionHeader
and prevent my app from crashing when I set the delegate for UICollectionView.
#import "HomeBannerReusableView.h"
#import "HomeBannerCell.h"
@interface HomeBannerReusableView () <UICollectionViewDelegate, UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@end
@implementation HomeBannerReusableView
- (void)awakeFromNib {
// Initialization code
[self.collectionView registerNib:[UINib nibWithNibName:@"HomeBannerCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBannerCell"];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
HomeBannerCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeBannerCellReusableView" forIndexPath:indexPath];
return cell;
}