Ios 如何在UICollectionViewSectionHeader中嵌入UICollectionView
我的应用程序正在崩溃,因为Ios 如何在UICollectionViewSectionHeader中嵌入UICollectionView,ios,objective-c,uiviewcontroller,uicollectionview,uicollectionviewdelegate,Ios,Objective C,Uiviewcontroller,Uicollectionview,Uicollectionviewdelegate,我的应用程序正在崩溃,因为 [UICollectionViewFlowLayout collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance. 这是因为我的委托方法位于我的UICollectionReusableView中,它不是视图控制器。如何将UICollectionView嵌入UICollectionViewSectionHeader中,并在为UICollectionView设置代理时
[UICollectionViewFlowLayout collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance.
这是因为我的委托方法位于我的UICollectionReusableView
中,它不是视图控制器。如何将UICollectionView嵌入UICollectionViewSectionHeader
中,并在为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;
}
#导入“HomeBannerReusableView.h”
#导入“HomeBannerCell.h”
@接口HomeBannerReusableView()
@属性(弱、非原子)IBUICollectionView*collectionView;
@结束
@HomeBannerReusableView的实现
-(无效)从NIB中唤醒{
//初始化代码
[self.collectionView注册表项nb:[UINib-nibWithNibName:@“HomeBannerCell”捆绑包:无]forCellWithReuseIdentifier:@“HomeBannerCell”];
}
-(NSInteger)collectionView:(UICollectionView*)collectionView项目编号截面:(NSInteger)截面{
返回1;
}
-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath{
HomeBannerCell*单元格=[collectionView dequeueReusableCellWithReuseIdentifier:@“HomeBannerCellReusableView”forIndexPath:indexPath];
返回单元;
}
无需将collectionView委托和数据源设置为UIViewController的子类。在我看来,您不小心将数据源设置为布局,而不是HomeBannerReusableView。检查设置位置(XIB、情节提要、代码)