문제 설명
StoryBoard를 사용하여 UITableViewCell 내부에 collectionView를 빠르게 빌드하는 방법 (How to use StoryBoard quick build a collectionView inside UITableViewCell)
아래 그림과 같이 tableView
셀 안에 collectionView
를 빌드합니다. 다음 IBOutlet
드래그 사용자 정의 UITableViewCell
에서 ServicePromotionItemCell 설정 UICollectionViewDataSource
.
메인 코드:
#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;
}
}
하지만 앱을 실행할 때 초기화되지 않는 것 같습니다. UICollectionView
, 내가 놓친 것이 있습니까? 도와주세요. 감사합니다 :)