Cell 文件里面 定义一个方法在.h文件中,下面是.m的实现
- (CGFloat)privateHeightForTableView{
[self setNeedsLayout];
[self layoutIfNeeded];
CGFloat rowHeight = 0.0;
for (UIView * bottomView in self.contentView.subviews) {
if (rowHeight < CGRectGetMaxY(bottomView.frame)) {
rowHeight = CGRectGetMaxY(bottomView.frame);
}
}
rowHeight += 10;//这个10 是cell间距可以根据需求调整,没间距就不用添加了.
return rowHeight;
}
在tableview的代理方法里面返回Cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
MYCell *cell = (MYCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
return [cell privateHeightForTableView] ;
}
网友评论