让CollectionView和TableView链接

时间:2017-06-12 03:26:38

标签: ios objective-c

我的CollectionView是在自定义的TableViewCell里面编写的。如何让CollectionView滚动时的高度,与TableView单元格的高度相同,并让CollectionView和TableView联动。

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _detailCollectionview = [[UICollectionView alloc]initWithFrame:CGRectMake(0,0, MainScreenWidth, MainScreenHeight)  collectionViewLayout:self.layout];
        _detailCollectionview.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_detailCollectionview];
        _detailCollectionview.delegate = self;
        _detailCollectionview.dataSource = self;

        [_detailCollectionview registerNib:[UINib nibWithNibName:@"WaterFallCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"detailcell"];

        [self.contentView addSubview:_detailCollectionview];
    }
    return self;
}

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

    WaterFallCollectionViewCell * cell = (WaterFallCollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"detailcell" forIndexPath:indexPath];
        HEPShopModel *model = self.modelArray[indexPath.row];
        [cell updateCellWithWaterFallModel:model];
         return cell;
}

0 个答案:

没有答案