- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LRPatientCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
//下面两句是关键
    cell.frame = tableView.bounds;
    [cell layoutIfNeeded];
    cell.item = self.array[indexPath.row];
    return cell;
}



- (void)setItem:(LRPatientCommentItem *)item {
    _item = item;
    // 标签
    [self.collectionView reloadData];
  
    [self layoutSubviews];//这句是关键
}

//这里获取collectionView 显示高度进行更新
- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat height = self.collectionView.collectionViewLayout.collectionViewContentSize.height;
    [self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(height);
    }];
    NSLog(@"height  %f",height);
}

 

参考

https://blog.csdn.net/zhanglizhi111/article/details/86292634

posted on 2021-04-08 17:14  懂事长qingzZ  阅读(808)  评论(0编辑  收藏  举报