1
내부 UICollectionView를 포함하는 방법

내 애플 때문에는 UICollectionViewSectionHeader

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

답변

1

collectionView delegate 및 dataSource를 UIViewController의 하위 클래스로 설정할 필요가 없습니다. 실수로 DataSource를 HomeBannerReusableView 대신 레이아웃으로 설정 한 것 같습니다. 설정 장소 (XIB, 스토리 보드, 코드)를 확인하십시오.