Alon Shlider
Alon Shlider

Reputation: 1308

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)

Upvotes: 1

Views: 96

Answers (3)

Nick
Nick

Reputation: 1444

In general you should have 4 constrains. I had the same problem with you for a while and for me the best solution that works the best is using percentage for height or width and then aspect ratio. For example the height of the element is going to be 20% of the view and then I use aspect ratio for the width etc. Also don't use stackView to all 5 elements. Leave the Movie Image outside the stackView.

Upvotes: 1

Rohit
Rohit

Reputation: 2326

The problem was that you used StackView but stackveiws also need some constraints.enter image description here

enter image description here

Here is the constraints I used to get the result I put 4 elements in stack view and give image to leading top width and height

Upvotes: 1

Shehata Gamal
Shehata Gamal

Reputation: 100541

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

Upvotes: 1

Related Questions