1

I have following, completely ruined design after I tried to implement dynamic-vertical UIStackView inside UITableViewCell: enter image description here

As you noticed, the label on top of this card is not fitting inside cell. Basically, this cell contains following UI components:

  1. The UILabel (that one which is not fitting). Constraints: top, leading, trailing.
  2. UIStackView(distribution&alignment fill) (it shows list of items with price). My custom view which is responsible for showing item's name and price is inserted to this stackview. Constraints: top to bottom of UILabel (that one which is not fitting), leading, trailing.
  3. The UIView (that divider line with constant height). Constraints: height constraint, leading, trailing, top to bottom of UIStackView.
  4. The two UILabel's (Full amount and total price. You can see it on image). Constraints: Top to bottom of divider line, leading, trailing and bottom constraints.

I set most intuitive constraints in XIB file. There are no errors or warnings. But anyway, the cell is not showing full content inside of it. I have following guesses:

  1. This cell is not alone. I also show other custom cells that have different intrinsic heights. I think iOS doesn't understand how to calculate the height of this cell. Then, I implemented methods estimatedHeightForRowAt and heightForRowAt by returning UITableView.automaticDimension. But, anyway, it didn't help.
  2. I think it is because of hugging or compression resistance priorities. That label is not fitting because it has equal compression resistance as other views. So, Auto Layout randomly decides which view should be ruined and just ruins that view. Ok, I set maximum compression resistance to that label and know it is fully shown. But, Auto Layout decides to destroy my UIStackView by clipping texts inside of it, even they have numberOfLines set to 0. I don't want my views to be clipped. I want them to be shown fully.

It seems serious problem. So, how can I solve it. Here is how constraints are set:

enter image description here

neo
  • 1,314
  • 2
  • 14
  • 34
  • Show a screen-cap of your xib layout.. make sure you include the document outline with **all** of the subviews and constraints showing. – DonMag Sep 22 '20 at 15:43
  • Done! I attached screenshot that shows constraints. – neo Sep 22 '20 at 16:01
  • Hmm... your constraints *look* correct. I'd have to see the source for your xib to inspect it closer. One tip: if you give your UI elements contrasting backgrounds it can make it much easier to see what might be wrong. I just put your layout together as close as I could match yours, with some sample data, and this is what I get: https://i.stack.imgur.com/NOxU7.png – DonMag Sep 22 '20 at 17:05
  • Yes, it seems everything should work, but it doesn't. Auto Layout and UITableView sucks. – neo Sep 22 '20 at 19:33
  • Compared to how we used to have to do it, auto-layout makes life incredibly easy. If you edit your post and include the source to your xib, I'll take a look at it. – DonMag Sep 22 '20 at 19:38

0 Answers0