如何在swift 4中动态增加单元格高度

Posted

技术标签:

【中文标题】如何在swift 4中动态增加单元格高度【英文标题】:how to increase cell height dynamically in swift 4 【发布时间】:2018-09-04 20:10:54 【问题描述】:

我是 swift 新手,我正在尝试创建一个学校项目。我面临的问题是我有多个单元格,我不知道如何增加单元格高度。我已经搜索过,但我无法理解如何做到这一点。 提前感谢您的帮助。

【问题讨论】:

更好的方法是利用自动布局和UITableView 的“估计”支持 - 请参阅Self-sizing Table View Cells 了解初学者 Using Auto Layout in UITableView for dynamic cell layouts & variable row heights 和 UITableViewCell auto height based on amount of UILabel text 可能重复 【参考方案1】:

实现如下表格查看方法:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat 

//return the size of your cell

    

如果您的单元格高度为 190,则只需在此处返回 190。

【讨论】:

以上是关于如何在swift 4中动态增加单元格高度的主要内容,如果未能解决你的问题,请参考以下文章