一个最简单的方法:
在tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath方法中根据cell里面内容的高度来改变,如下代码:
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return ((MyBankCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath]).main.frame.size.height;
}
注意:这里要调用viewcontroller的方法来获取cell,若直接用tableview的方法cellForRowAtIndexPath来获取会造成crash。
本文介绍了一个简单的自适应UITableView Cell高度的方法。通过在tableView:heightForRowAtIndexPath:方法中动态计算cell内容的实际高度,实现UITableViewCell高度的自动调整。
8456

被折叠的 条评论
为什么被折叠?



