1

Мое приложение рушится из-заКак вставлять UICollectionView внутри UICollectionViewSectionHeader

[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; 
} 

ответ

1

Нет необходимости устанавливать collectionView delegate и dataSource в подкласс UIViewController. Мне кажется, что вы случайно установили dataSource в свой макет вместо HomeBannerReusableView. Проверьте место, где вы его установили (XIB, Раскадровка, код).

Смежные вопросы