Search code examples
iosswiftxcodexib

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


enter image description here

I have a custom xib file and am trying to load a picture when the table view is launched. However I get this error of multiple constraints. I have set the row height of the tableviewcell automatic, and the sum of three views that comprise the xib view add up to 408 pixels. I have also tried setting the row height to 409 given the error said 408.333 pixels for the cell, however this did not help.


Solution

  • This is a common issue, particularly when using UIStackViews in table view cells.

    The problem is that as auto-layout is "doing its thing," it has to make several passes to calculate the complete layout.

    When it encounters a stack view in a (non-fixed-height) cell, it needs to deal with the various heights of the stackView's arranged subviews, the table width and height, and the cell height. In addition, because a point on a @2x scale device uses 2 pixels, and on a @3x scale device it uses 3 pixels, auto-layout has to manipulate heights around one-half-points and one-third-points, respectively.

    I think I would say it's not surprising that at some point during those calculations auto-layout prints error / warning messages to the console.

    Setting the Priority on the stack view's Bottom constraint to 999 allows auto-layout to, I guess, temporarily break the constraint without coughing up the warning.

    So... is it a Bug? Or is it Unavoidable? Only Apple knows for sure. :)