我有一个带有原型单元格的表格视图,在这个单元格中我有图像视图和一些文本。文本标签是原型单元格中的一行,但有时它不止一行,我在调用服务器后将数据加载到表视图中。情节提要线中的标签设置为0,换行符设置为换行。我也尝试过http://candycode.io/automatically-resizing-uitableviewcells-with-dynamic-text-height-using-auto-layout/
但没有效果。如果我使用Using Auto Layout in UITableView for dynamic cell layouts & variable row heights,一切都会正常工作,因为标签文本是预定义的,但是我从服务器加载数据,并在API调用之后重新加载tableView,然后标签只有一行。
发布于 2016-04-12 13:10:06
你应该使用UITableViewAutomaticDimension
提供一个显示动态内容的解决方案。
在viewDidLoad
中使用以下代码
tableView.estimatedRowHeight = YourTableViewCellHeight
tableView.rowHeight = UITableView.automaticDimension
希望能有所帮助。:)
发布于 2016-04-12 13:11:23
确保UILabel高度约束不是常量,如果是常量,则必须在属性检查器中将关系设置为大于或等于
确保根据您的设置设置UITableViewestimate行高。
tableView.estimatedRowHeight = 85
并在UITableViewCell
类中编写
cell.lbl_name.sizeToFit()
cell.lbl_name.numberOfLines = 0
确保您的UITableViewDelegate
方法
func tableView(tableView: UITableView,
heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableView.automaticDimension
}
https://stackoverflow.com/questions/36574052
复制相似问题