简体   繁体   English

UITableViewCell没有扩展到适合UILabel的高度,我在做什么错?

[英]UITableViewCell is not expanding to fit height of UILabel, what am I doing wrong?

What I want is my UITableViewCell to expand/shrink based on the height of the UILabel inside. 我想要的是UITableViewCell基于UILabel内部的高度进行扩展/缩小。

I have tried just about every solution I could find and it's not working. 我已经尝试了几乎所有可以找到的解决方案,但都无法正常工作。 Maybe I have some setting that's preventing it. 也许我有一些阻止它的设置。

Here is a screenshot of the UITableViewCell settings: 这是UITableViewCell设置的屏幕截图:

在此处输入图片说明

For the UILabel inside, Lines is set to 0 and Line Break to Word Wrap . 对于内部的UILabel ,将Lines设置为0并将Line BreakWord Wrap

In the UIViewController where I'm showing the table view, I am setting this in viewDidLoad() : 在显示表格视图的UIViewController中,我在viewDidLoad()

tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 44
tableView.reloadData()

And in cellForRowAt after dequeuing the cell I'm doing (instructionText being the UILabel): 并在我正在做的单元出队后在cellForRowAt (instructionText是UILabel):

cell.instructionText.numberOfLines = 0

I've seen this in many tutorials and it works, why not for these cells? 我已经在许多教程中看到了这一点,并且效果很好,为什么不为这些单元格呢? The content comes out like this: 内容如下所示:

在此处输入图片说明

This is driving me crazy! 这真让我抓狂! Thanks for any help! 谢谢你的帮助!

EDIT: Here are the UILabel settings: 编辑:这是UILabel设置:

在此处输入图片说明

Please check your label constraints 请检查您的标签限制

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM