4

The layers: UITableViewCell -> UIStackView -> UILabel, table height is set to automatic dimension.

enter image description here

Run it, everything is fine

enter image description here

After some scrolling, the bottom of the multiline label gets cut off

enter image description here

UILabel and stack view settings:

enter image description here enter image description here

lay out constraints for the stack view:

enter image description here

I've tried to set the line break to word wrap, call sizeToFit on the label, neither of them works for me. Any clues?

jc127
  • 343
  • 2
  • 13
  • Add estimatedRowHeight for TableViewCell – Mohammad Sadiq Aug 18 '17 at 06:29
  • estimatedRowHeight is already added, just changed it to different values, still doesn't work. @MohammadSadiq – jc127 Aug 18 '17 at 06:44
  • 1
    `prepareForReuse` is implemented for your cell? – dirtydanee Aug 18 '17 at 06:56
  • how would I use prepareForReuse in this case? I'm not very familiar with it. @dirtydanee – jc127 Aug 18 '17 at 07:50
  • check out this answer: https://stackoverflow.com/questions/9362713/how-to-use-prepareforreuse-method . Basicly, you need to reset every labels text value to `nil` in this function. If you need, i can write a small example as an answer. – dirtydanee Aug 18 '17 at 08:16
  • I tried it, it didn't work, also, the documentation for prepareForReuse states "For performance reasons, you should only reset attributes of the cell that are not related to content, for example, alpha, editing, and selection state...tableView(_:cellForRowAt:) should always reset all content when reusing a cell", so there really isn't a point to use it, I suppose. @dirtydanee – jc127 Aug 18 '17 at 22:36

2 Answers2

1

Since the problem occurs because of scrolling, this seems to be the problem related to TableView reusing the cells on scrolling. Hence reset all the values of cell that you are using (which includes dimensions as well if any). On scrolling, the current cell content gets displayed in some other cell which is being reused.

Techie
  • 61
  • 1
  • 2
0

One way I have solve that kind of problems in the past is to put the UILabel inside a UIView as a container view. Then put this container inside the UIStackView instead of putting the label directly in the stack view.

You can also try to play around with compression resistance priority because the label seems to be shrinking because its compression resistance is not high enough.

Kedio
  • 105
  • 9