如何使用 StoryBoard 在 UITableViewCell 中快速构建一个 collectionView
How to use StoryBoard quick build a collectionView inside UITableViewCell
我在tableView
单元格中构建了一个collectionView
,如下图所示:
然后在自定义 UITableViewCell
中拖动一个 IBOutlet
名为 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
,我是不是漏掉了什么?
请帮忙 me.Thanks :)
检查是否导入了集合视图数据源,检查您的委托是否分配给了特定的视图控制器,检查数据是否为空或者它有一些您想要显示的值
我在tableView
单元格中构建了一个collectionView
,如下图所示:
UITableViewCell
中拖动一个 IBOutlet
名为 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
,我是不是漏掉了什么?
请帮忙 me.Thanks :)
检查是否导入了集合视图数据源,检查您的委托是否分配给了特定的视图控制器,检查数据是否为空或者它有一些您想要显示的值