Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在UICollectionViewSectionHeader中嵌入UICollectionView_Ios_Objective C_Uiviewcontroller_Uicollectionview_Uicollectionviewdelegate - Fatal编程技术网

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、情节提要、代码)