アプリがクラッシュする理由
[UICollectionViewFlowLayout collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance.
UICollectionReusableView
これは、デリゲート メソッドがビュー コントローラーではないmy 内にあるためです。UICollectionView のデリゲートを設定したときにUICollectionView を内部に埋め込み、UICollectionViewSectionHeader
アプリがクラッシュしないようにするにはどうすればよいですか。
#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;
}