在swift中设置tableview单元格行高时,我很惊讶,滚动行高正在更改,请检查屏幕截图。swift - Tableview根据内容快速动态设置行高?-LMLPHP
第一次,它的滚动完美的多次滚动的高度是不正确的。我使用的自定义TableView单元格太多
在视图中加载
我加了这个

self.tableView.rowHeight = UITableViewAutomaticDimension

并添加了这些委托方法。
 func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
    {
            return UITableViewAutomaticDimension
    }

    func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
    {
        return UITableViewAutomaticDimension
    }

有谁能指导我以正确的方式实现这个目标吗?

最佳答案

你可以试试这样的:

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 160

在故事板中,需要为标签设置顶部和底部约束。没别的了。

关于swift - Tableview根据内容快速动态设置行高?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42315106/

10-14 21:44
查看更多