由于
,我的应用程序崩溃了[UICollectionViewFlowLayout collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance.
这是因为我的委托方法在我的UICollectionReusableView
内,而不是视图控制器。如何在UICollectionViewSectionHeader
中嵌入UICollectionView,并在为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;
}
答案 0 :(得分:1)
无需将collectionView委托和dataSource设置为UIViewController的子类。对我来说,你不小心将dataSource设置为你的布局,而不是HomeBannerReusableView。检查您设置它的位置(XIB,故事板,代码)。