方法有很多,有通过内容高度,经过代理回调,刷新的,甚至还有计算cell个数,然后根据cell大小计算的,这里推荐iOS 8新特性,通过AutoLayout,利用内容将cell撑起来;
关键代码:
viewcontroller中:
self.tableview.estimatedRowHeight = 40;
self.tableview.rowHeight = UITableViewAutomaticDimension;
cell中:这里要说明,给collectionview上下左右添加约束,再加上高度约束,就是通过更新collectionview的高度约束,将cell撑起来的
cell根据数据源赋值方法中:
self.frame = [UIScreen mainScreen].bounds;
[self setNeedsLayout];
[self layoutIfNeeded];
[self.collectionView reloadData];
[self updateTheCollectionview:self.collectionView.collectionViewLayout.collectionViewContentSize.height];
转载于:https://www.cnblogs.com/liuzicheng/p/6206798.html