// this is the cell height cache; obviously you don't want a static size array in production
var itemHeights = [CGFloat](count: 1000, repeatedValue: UITableViewAutomaticDimension)
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
if itemHeights[indexPath.row] == UITableViewAutomaticDimension {
itemHeights[indexPath.row] = cell.bounds.height
}
// fetch more cells, etc.
}
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return itemHeights[indexPath.row]
}
但是没有解决动态高度,如某个文案 有一个less和more点击的