2

I have a UIView in a UITableViewCell. in the view, I have a UITextView and a UIView. They are both auto constraint on all 4 sides.

The UIView has a height constraint. I would like to update the height constraint prorrammatically. I made a outlet of the height constraint so I can change it.

Here is my code:

CGRect frame = self.myView.frame;
frame.size.height = 50;
frame.size.width = self.myView.frame.size.width;
self.myView.frame = frame;
self.viewHeight.constant = 50;

[myTableView reloadData];

When I run this code, it works perfectly, but I get an error: (I'm pretty new to objective c, so I don't understand what it's trying to say.)

2015-01-26 15:25:43.408 myApp[1449:55334] 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:0x7fb07853ac20 V:[UIView:0x7fb0784dbb80(50)]>",

    "<NSLayoutConstraint:0x7fb0785bd170 V:|-(0)-[UITextView:0x7fb07896de00]   (Names: '|':UIView:0x7fb07857fb70 )>",

    "<NSLayoutConstraint:0x7fb0785bd260 V:[UITextView:0x7fb07896de00]-(3)-[UIView:0x7fb0784dbb80]>",

    "<NSLayoutConstraint:0x7fb0785bd350 V:[UIView:0x7fb0784dbb80]-(0)-|   (Names: '|':UIView:0x7fb07857fb70 )>",

    "<NSLayoutConstraint:0x7fb0785bd5b0 UILabel:0x7fb0785150f0'info:'.top == UITableViewCellContentView:0x7fb078581400.topMargin>",

    "<NSLayoutConstraint:0x7fb0785bd650 UITableViewCellContentView:0x7fb078581400.bottomMargin == UIView:0x7fb07857fb70.bottom + 1>",

    "<NSLayoutConstraint:0x7fb0785bd6f0 V:[UILabel:0x7fb0785150f0'info:']-(8)-[UIView:0x7fb07857fb70]>",

    "<NSLayoutConstraint:0x7fb078704f20 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fb078581400(77)]>"

)



Will attempt to recover by breaking constraint 

<NSLayoutConstraint:0x7fb07853ac20 V:[UIView:0x7fb0784dbb80(50)]>



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.
  • "Unable to simultaneously satisfy constraints." It means that the autolayout system is not able to meet your constraints because the constraints contain conflicts. Try to examine your constraints code – taocp Jan 26 '15 at 23:49
  • All other constraints are made in the storyboard and there are no errors there –  Jan 26 '15 at 23:50

1 Answers1

0

You programmaticlly change the height constraint to 50. It is unsatisfied with UIView-Encapsulated-Layout-Height constraint(77), which is set by iOS for UITableViewCellContentView.

ljk321
  • 16,242
  • 7
  • 48
  • 60
  • In heightForRowAtIndexPth my return statement is as follows: return txtView.frame.size.height + self.myView.frame.size.height + 44 - 0.5; –  Jan 27 '15 at 00:55
  • @MikeRally Is `txtView.frame.size.height + self.myView.frame.size.height + 44 - 0.5` suppose to be exactly `50` ? Anyway, I don't recommand mixing up storyboard constraints and programmaticlly set constraints. It tends to cause many unexpected problems. – ljk321 Jan 27 '15 at 01:12
  • no. self.myView.frame.size.height is 50. I don't usually do it, but I had to assign a height to myView in the storyboard, and I'm trying to change the height programamtically. –  Jan 27 '15 at 01:15
  • @MikeRally To remove the warning, you can try to remove previous constraint before assigning a new one. This answer http://stackoverflow.com/a/27621707/3562486 may be helpful. – ljk321 Jan 27 '15 at 01:19