Swift动态表格单元格高度 [英] Swift dynamic table cell height

查看:177
本文介绍了Swift动态表格单元格高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有原型单元格的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

Read more from here

Hope it helps. :)

这篇关于Swift动态表格单元格高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆