使用 ios8 自动调整单元格的动态 UITableView 行高和最大行高?

Dynamic UITableView rowheight and max row height using ios8 auto-resizing cell?

我想在具有最大行高的 UITableView 中实现动态行高,以将行限制为不超过 10 行(该行只有一个标签)。如果一行少于 10 行,则其内容将被完整显示。如果超过 10 个,将显示 10 行并截断。 我可以使用 iOS8 的自动调整大小功能来实现吗?如果是,如何?

我一整天都在为 iOS7 上的动态单元格使用 UITableView 中的自动布局,它使用虚拟 UITableViewCell 和 heightForRowAtIndexPath: 并且非常复杂。失败!

有一个简单的方法可以做到这一点:

cell.ContentLabel.numberOfLines = 10;

是的,configureCell 中的一行简单代码。它将标签限制在 10 行,并且它是具有 iOS8 自动调整大小的动态行高:

self.tableView.estimatedRowHeight = 100.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;