UITableViewCell vertical layout custom constraints causing an error

When I run my application on iPhone, I get the following errors. When I run it in the simulator, I do not. If I remove -12-| then the cell height will decrease to about 30 pixels. And the user interface breaks. Can someone help me and tell me why?

thanks

 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:0x170285ff0 V:|-(12)-[UIImageView:0x1741ec200] (Names: '|':UITableViewCellContentView:0x17419c7d0 )>", "<NSLayoutConstraint:0x170286040 V:[UIImageView:0x1741ec200(200)]>", "<NSLayoutConstraint:0x170286090 V:[UIImageView:0x1741ec200]-(12)-| (Names: '|':UITableViewCellContentView:0x17419c7d0 )>", "<NSLayoutConstraint:0x174881f40 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x17419c7d0(224)]>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x170286090 V:[UIImageView:0x1741ec200]-(12)-| (Names: '|':UITableViewCellContentView:0x17419c7d0 )> 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. Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell content view. We're considering the collapse unintentional and using standard height instead. Unable to simultaneously satisfy constraints. 

In a custom UITableViewCell I defined layout constraints as follows:

 _imgView.translatesAutoresizingMaskIntoConstraints = NO; [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-15-[imageView]-15-|" options:0 metrics:nil views:@{ @"imageView": _imgView }]]; [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-12-[imageView(200)]-12-|" options:0 metrics:metrics views:@{ @"imageView" : _imgView }]]; 

--- EDIT ---

In response to the contentView.bounds suggestion: In my UITableViewController I implement the following:

 _tableView.rowHeight = UITableViewAutomaticDimension; _tableView.estimatedRowHeight = 30.0f; 

Thus, zero height should not be a problem.

+5
source share
1 answer

The initial cell height is probably less than the vertical limits. This creates an initial height conflict until the contentView frame changes.

You can work around this problem using one of the following methods:

  • Increase the height of the cell in the storyboard so that it initially matches the content.

  • Resize the cellView content to a larger size:

    self.contentView.bounds = CGRectMake(0, 0, 99999, 99999);

You will find more information in the answers to this auto layout question .

Update

The β€œCannot satisfy constraints at the same time” conflict is between the imageView constraints, which are trying to set the cell height to 225 points, and a fixed height is trying to set the cell height to 224 points.

Your vertical image limits use 224 (12 + 200 + 12) dots. The tableView separator uses 1 point. Thus, the cell height should be 225 points for all restrictions that must be met.

+1
source

Source: https://habr.com/ru/post/1208731/


All Articles