5

when I run my app on an iPhone I get the following errors. When I run it in the simulator I do not. If I take the -12-| away then the cell's height collapses to something like 30 pixels. And the UI 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's content view. We're considering the collapse unintentional and using standard height instead.
Unable to simultaneously satisfy constraints.

In a custom UITableViewCell I defined the 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;

So a zero height, should not be an issue.

Joseph
  • 9,171
  • 8
  • 41
  • 67
  • Hi as per your question it seems that the constraints are breaking on device but not it simulator. It seems that you are trying to set imageview height in cell. Can you please add image of simulator and from device along with log screen when you run on simulator and in device. As the only reason it seems is due to table view cell height. – Dhaivat Vyas Dec 13 '14 at 15:13

1 Answers1

1

The initial height of the cell is likely smaller than the vertical constraints. This creates an initial height conflict until the contentView's frame changes.

You can work around this issue using one of the following approaches:

  • Increase the cell's height in the storyboard to initially fit the content.

  • Change the bounds of the cell's contentView to a larger size:

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

You'll find more details in the answers to this auto layout question.

Update:

The "Unable to simultaneously satisfy constraints" conflict is between the imageView constraints trying to set the cell's height to 225 points, and the fixed height trying to set the cell height to 224 points.

Your imageView vertical constraints use 224 (12 + 200 + 12) points. The tableView separator uses 1 point. So the cell height needs to be 225 points for all constraints to be met.

Community
  • 1
  • 1
  • Hi, sorry for the late response. The error still appears. – Joseph Dec 19 '14 at 13:57
  • I am not using storyboards. The UI is code based. The cell height has to be 224 because of the Layout Constraint I defined `V:|-12-[imageView(200)]-12-|` – Joseph Dec 20 '14 at 03:40
  • What I don't understand ist why there is an initial height in the first place? I don't implement `- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath` – Joseph Dec 20 '14 at 06:15
  • I just implemented `- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"Row Height: %f", _tableView.rowHeight); }` to find a spot after the tableView has been drawn and it logs `-1.0000` – Joseph Dec 20 '14 at 06:26