1
votes

While I seem to have taken the gist of setting the view constraints on UIViews of storyboards, I just can't seem to figure out why constraints are not properly working in a dynamic cell prototype ContentView's subviews.

The cell is pretty simple: A UIImageView background that fills the entire cell, in front of it another UIImage and a label as following:

The background UIImageView has the following 4 constraints: 0 fixed to: trail, bottom, top and leading space to superview

The profile picture image has a fixed width and height and a constant 13pts space to leading superview and has a vertical center in container

The Label has an 8pt leading space to the profile pic and trailing space to superview, and has a vertical center in container.

This is what I am getting:

Did I miss something? I researched the issue but no answer solved the issue. However, I tried adding the following lines in the cellForRowAtIndexPath after loading the cell:

cell.setNeedsUpdateConstraints()
cell.updateConstraintsIfNeeded()

which gave the following errors at runtime:

Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"NSLayoutConstraint:0x7fe5434852c0 H:[UIImageView:0x7fe543484450(75)]", "NSLayoutConstraint:0x7fe5436c5cd0 H:|-(12)-[UIImageView:0x7fe543484450] (Names: '|':UITableViewCellContentView:0x7fe5434820f0 )", "NSLayoutConstraint:0x7fe5436c34e0 H:[UILabel:0x7fe543487430'Joseph']-(8)-| (Names: '|':UITableViewCellContentView:0x7fe5434820f0 )", "NSLayoutConstraint:0x7fe5436bcca0 H:[UIImageView:0x7fe543484450]-(8)-[UILabel:0x7fe543487430'Joseph']", "NSLayoutConstraint:0x7fe5436cb110 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x7fe5434820f0(0)]" )

Will attempt to recover by breaking constraint NSLayoutConstraint:0x7fe5434852c0 H:[UIImageView:0x7fe543484450(75)]

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in UIKit/UIView.h may also be helpful.

Any clues?

1

1 Answers

1
votes

Well, problem is priorities.

You have background image, which has some size according to image you put into it and than there is a profile picture with fixed height and constant space 13pts top and bottom.

Table may have separator and that one is adding extra space.

So advice: lower for example bottom 13pts constrains from 1000 to 750. That should remove warning.