iOS UITableViewCell 高度自适应的解决方案

// 设置预加载cell高度
tableView.estimatedRowHeight = 55;
// 自动适应cell高度
tableView.rowHeight = UITableViewAutomaticDimension;
1
2
3
4
或者

– (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 55;
}

– (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}