Search code examples
iosswifttableviewheightnslayoutconstraint

I have a problem understanding the logic of how to work with autolayout


Here is my repository of the project:

https://github.com/alonsd/MoviesApi

The reason I am giving here the entire project is because the problems lies inside a .xib file and is not a code issue, therefor I think this would be the better way of me getting help for this issue.

I am facing the following issue when trying to populate a custom cell inside a table view from some data that I have.

Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want.

So I looked for solutions over this site and came across a nice debugging way to figure out what is wrong, I made an extension that overrides the description var of NSLayoutDescription and prints out the id and the constant for faster and better understanding where the problem lies. So apparently the error goes away once I delete the height and weight from my img inside my .xib file, but that would make the image disappear completely from the .xib. What is the problem specifically with the way I did my layout? I tried also to use "reset to suggested constraints" on my .xib file and it makes the error go away but it also makes every cell height to be huge once I scroll up and down.

And for another issue I am facing - I think I am not sure about how constraints work. That is because when you look at my xib file you can see a major space between the image and the right end of the cell, but in the list itself there is nothing so I am really confused about that.

This is the image of the simulator with the tableview -

https://i.sstatic.net/c71DQ.jpg

and this is the image of my .xib file with the spaces that actually do not appear in the simulator -

https://i.sstatic.net/xSK5E.jpg

(I could not figure out how to put them directly in the post)


Solution

  • 1- Remove width & height constraints here

    enter image description here

    2- Remove containerView leading constraint here

    enter image description here 3- Add a trailing constraint to the stackview

    4- Add a value to the stackview leading constant

    enter image description here

    5- select all labels and adjust vertical content hugging to 1000

    enter image description here

    6- select the textContainer stack and set spacing to say 20