2

I build a collectionView inside a tableView cell,like below picture show: then drag a IBOutlet in Custom UITableViewCell named ServicePromotionItemCell setting UICollectionViewDataSource.

main code:

#import "ServicePromotionCollectionView.h"
#import <HexColor.h>
@interface ServicePromotionItemCell ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (strong, nonatomic) IBOutlet ServicePromotionCollectionView *promotionCollectionView;
@end

@implementation ServicePromotionItemCell

- (void)awakeFromNib {
    UICollectionViewFlowLayout* flowLayout = [[UICollectionViewFlowLayout alloc]init];

    _promotionCollectionView = [[ServicePromotionCollectionView alloc] initWithFrame:self.bounds collectionViewLayout:flowLayout];
    _promotionCollectionView.delegate = self;
    _promotionCollectionView.dataSource = self;
    [_promotionCollectionView registerClass:ServicePromotionCollectionViewCell.self forCellWithReuseIdentifier:@"ServicePromotionCollectionCell"];
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return 3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ServicePromotionCollectionCell" forIndexPath:indexPath];

    return cell;
}
}

But when I run app,It seem not init UICollectionView, does I miss something? Please help me.Thanks :)

enter image description here

james
  • 643
  • 4
  • 24

1 Answers1

1

check collection view data source is imported or not,check your delegate is assigned to particular view controller,check the data is nill or it have some values which you want to display it