Swift动态表格单元格高度 [英] Swift dynamic table cell height
问题描述
我有原型单元格的tableview,单元格中有
我有imageview,下面是一些文本。
文本标签是原型单元格中的一个,但有时它不止一行,我在服务器调用后将数据加载到表视图中。
storyboard行中的标签设置为0,Line Break设置为Word Wrap。
我也试过 http:/ /candycode.io/automatically-resizing-uitableviewcells-with-dynamic-text-height-using-auto-layout/
但没有效果。
如果我使用使用UITableView中的自动布局,用于动态单元布局和变量行高度
一切正常,因为标签文本是预定义的,但我正在从服务器加载数据,我在API调用后重新加载tableView,然后标签只是一行。
您应该使用 UITableViewAutomaticDimension
提供显示动态内容的解决方案。
在中使用以下代码viewDidLoad
:
tableView.estimatedRowHeight = YourTableViewHeight
tableView.rowHeight = UITableViewAutomaticDimension
<希望它有所帮助。 :)
I have tableview with prototype cell, in the cell I have imageview and some text under. The text label is one laine in the prototype cell, but sometimes it is more than one line, I'm loading the data to the table view after server call. The label in storyboard Lines are set to 0 and Line Break to Word Wrap. I also tried http://candycode.io/automatically-resizing-uitableviewcells-with-dynamic-text-height-using-auto-layout/
but no effect. If I use Using Auto Layout in UITableView for dynamic cell layouts & variable row heights everything works because the label text is predefined, but I'm loading the data from server and I reload the tableView after the API call, and then the label is just one line.
You should use UITableViewAutomaticDimension
provides a solution for displaying dynamic content.
Use below code in viewDidLoad
:
tableView.estimatedRowHeight = YourTableViewHeight
tableView.rowHeight = UITableViewAutomaticDimension
Hope it helps. :)
这篇关于Swift动态表格单元格高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!