如何使用StoryBoard在UITableViewCell中快速构建一个collectionView [英] How to use StoryBoard quick build a collectionView inside UITableViewCell

查看:114
本文介绍了如何使用StoryBoard在UITableViewCell中快速构建一个collectionView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 tableView 单元格中构建了一个 collectionView ,如下图所示:

然后在自定义 UITableViewCell 中拖动 IBOutlet 命名为ServicePromotionItemCell设置 UICollectionViewDataSource

I build a collectionView inside a tableView cell,like below picture show: then drag a IBOutlet in Custom UITableViewCell named ServicePromotionItemCell setting 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;
}
}

但是当我运行app时,它似乎不是init UICollectionView ,我错过了什么吗?
请帮帮我。谢谢:)

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

推荐答案

检查集合视图数据源是否已导入,检查您的委托是否已分配给特定视图控制器,检查数据是否为nill或者它有一些要显示的值

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

这篇关于如何使用StoryBoard在UITableViewCell中快速构建一个collectionView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆