swift - Tableview根据内容快速动态设置行高?

标签 swift uitableview height tableviewcell

在swift中设置tableview单元格行高时,我很惊讶,滚动行高正在更改,请检查屏幕截图。enter image description here
第一次,它的滚动完美的多次滚动的高度是不正确的。我使用的自定义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/

相关文章:

带有不透明标题的 UITableViewStylePlain

ios - 我在使用协议(protocol)传递数据时做错了什么

javascript - 根据内容高度为多个 iFrame 设置唯一高度

php - 在 Ajax 将内容扩展到屏幕之外后如何找到页面高度?

具有多个原型(prototype)单元格的 Swift TableView 未显示所有行

ios - 无法更改 UITableView 中节标题的文本属性

ios - Swift:在自定义 TableViewCell 上设置 UITextfieldDelegate

android - Xamarin.Forms.Shell : how to get the bottom TabBar height?

iOS :How can I make a double variable change from 0.0 to 1.0

ios - 如何在 Swift 中使用 NSURLSession downloadTask 顺序下载多个文件