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

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

问题描述

我有带有原型单元格的tableview,在单元格中,我有 imageview 和一些文本.文本标签是原型单元格中的一行,但有时不止一行,我在服务器调用后将数据加载到表视图.情节提要 Lines 中的标签设置为 0,Line Break 设置为 Word Wrap.我也试过 http://candycode.io/automatically-resizing-uitableviewcells-with-dynamic-text-height-using-auto-layout/

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/

但没有效果.如果我使用 在 UITableView 中使用自动布局用于动态单元格布局 &可变行高一切正常,因为标签文本是预定义的,但我正在从服务器加载数据,并在 API 调用后重新加载 tableView,然后标签只是一行.

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 提供了一个显示动态内容的解决方案.

You should use UITableViewAutomaticDimension provides a solution for displaying dynamic content.

viewDidLoad中使用以下代码:

tableView.estimatedRowHeight = YourTableViewCellHeight
tableView.rowHeight = UITableView.automaticDimension

从这里阅读更多内容

希望有帮助.:)

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

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