5

Sometimes I keep getting errors like these - without any hint to which TextView or Button is meant:

    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:0x11d748d0 V:[UITextView:0xc1bb000(65)]>",
    "<NSLayoutConstraint:0x11d77620 V:[UIButton:0x11d71cf0(44)]>",
    "<NSLayoutConstraint:0x11d7be30 V:[UIButton:0x11d79e70(43)]>",
    "<NSLayoutConstraint:0xa1980d0 V:|-(134)-[UITextView:0xc1bb000]   (Names: '|':UIView:0xa1afba0 )>",
    "<NSLayoutConstraint:0xa199ed0 UITextView:0xc1bb000.centerY == UIButton:0x11d71cf0.centerY>",
    "<NSLayoutConstraint:0xa199e50 V:[UIButton:0x11d79e70]-(61)-[UIButton:0x11d71cf0]>",
    "<NSLayoutConstraint:0xa199cb0 V:|-(40)-[UIButton:0x11d79e70]   (Names: '|':UIView:0xa1afba0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x11d748d0 V:[UITextView:0xc1bb000(65)]>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

Is there a way to identify the constraint in the code that is causing the crash?

The text:

  Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x11d748d0 V:[UITextView:0xc1bb000(65)]>

unfortunately doesn't help much, since I do not have any idea which constraint this is in code

user387184
  • 10,953
  • 12
  • 77
  • 147
  • possible duplicate of [Unable to simultaneously satisfy constraints - No constraints in place](http://stackoverflow.com/questions/14327145/unable-to-simultaneously-satisfy-constraints-no-constraints-in-place) - there is help there on reading these logs – jrturton Apr 08 '13 at 09:05

1 Answers1

7

You read them like this:

<NSLayoutConstraint:0x11d748d0 V:    [UITextView:0xc1bb000(65)]>
 ^ Constraint type  ^ Address  ^Axis ^Description in VFL
                      (of constraint)

So this is a constraint forcing the textview to be 65 points high. In there you also have a constraint pinning this text view to 134 points from its superview's top edge:

<NSLayoutConstraint:0xa1980d0 V:|-(134)-[UITextView:0xc1bb000]   (Names: '|':UIView:0xa1afba0 )>

And a constraint pinning the Y center of the text view to the Y center of a button:

<NSLayoutConstraint:0xa199ed0 UITextView:0xc1bb000.centerY == UIButton:0x11d71cf0.centerY>

And a constraint pinning the button itself to a specific vertical location:

<NSLayoutConstraint:0xa199e50 V:[UIButton:0x11d79e70]-(61)-[UIButton:0x11d71cf0]>

It is likely that you didn't want all these constraints. Here you have two constraints that are trying to position the text view vertically (based from the button, and based on absolute spacing from the top of the superview).

Somewhere in your app you must have a view with a text field and two buttons. If you break on all exceptions you can log out the various addresses given in the log and find out the superviews and so on if you're not sure, but hopefully you'll be able to work it out from this.

Sometimes it is helpful to copy the log into a text editor and find / replace the addresses with words so that it is easier to read.

jrturton
  • 118,105
  • 32
  • 252
  • 268
  • 4
    Thank you very much for this detailed explanation. I also just put a statement like NSLog(@"ok_btnTV %p",_ok_btnTV); now in my viewDidAppear to find the view in question. Now it took not longer than 10 secs to find the problem! - what an archaic way though to find such a problem having this "super advanced UI builder"... Thank you very much again! – user387184 Apr 08 '13 at 09:20