Auto Layout Constraints Issue in UITableView - ios

With the help of Auto Layout I had implemented the views programmatically to handle the different design layouts for iPhone 4, 5 and 6. The program works good in all the views except UITableView. I am getting the below constraints issue in my console.
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:0x178be740 V:|-(0)-[UILabel:0x165413b0] (Names: '|':UITableViewCellContentView:0x16541ac0 )>",
"<NSLayoutConstraint:0x178b5910 V:[UILabel:0x165413b0(40)]>",
"<NSLayoutConstraint:0x178a0ac0 V:[UILabel:0x165413b0]-(NSSpace(8))-[UIView:0x1789e5d0]>",
"<NSLayoutConstraint:0x178a0af0 V:[UIView:0x1789e5d0(1)]>",
"<NSLayoutConstraint:0x178a0b20 V:[UIView:0x1789e5d0]-(0)-| (Names: '|':UITableViewCellContentView:0x16541ac0 )>",
"<NSLayoutConstraint:0x178ab4f0 V:|-(10.5)-[UIImageView:0x1789e4c0] (Names: '|':UITableViewCellContentView:0x16541ac0 )>",
"<NSLayoutConstraint:0x178b9ca0 V:[UIImageView:0x1789e4c0(19)]>",
"<NSLayoutConstraint:0x178b9cd0 V:[UIImageView:0x1789e4c0]-(10.5)-| (Names: '|':UITableViewCellContentView:0x16541ac0 )>"
)
I tried with several posts and failed to get rid of the constraints. Could any one suggest on this?
Updated code
//MyCustomeListCell.h
UILabel *listTitle;
UIImageView *listImage;
UIView *listSplitter;
//MyCustomListCell.m
NSDictionary *viewsDictionary =#{#"listTitle": self.listTitle,#"listImage" : self.listImage,#"listSplitter": self.listSplitter};
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|[listTitle(40)]-[listSplitter(1)]|" options:0 metrics:nil views:viewsDictionary]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|[listSplitter]|" options:0 metrics:nil views:viewsDictionary]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|-10.5-[listImage(19)]-10.5-|" options:0 metrics:nil views:viewsDictionary]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|-15-[listTitle]-15-[listImage(13)]-20-|" options:0 metrics:nil views:viewsDictionary]];

This format string,"V:|-10.5-[listImage(19)]-10.5-|" is saying that you want the imageView to be 10.5 points separated from the top and bottom of its superview, but also to be 19 points tall. So, unless the superview is exactly 40 points tall in all screen sizes, this will cause an error.
Same with this one, "V:|[listTitle(40)]-[listSplitter(1)]|" This one will only work if the superview is 49 points tall (40 + 8 for the dash (I think) + 1).
To fix these, you need to not have the system so constrained. Depending on what you want, you could remove the "|" from one end of those format strings, or get rid of the size setting.

There is much simpler way, without using constrains but autoresizingMask:
self.autoresizingMask = UIViewAutoresizingFlexibleWidth;

Related

Custom UITableViewCell vertical layout constraints causing error

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.
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.

Autolayout constraints warning "Will attempt to recover by breaking constraint"

I am setting some specifics constraints for iPhone 4 when the app is ran on this device. Everything look great in terms of alignment and everything.
But, I am getting an error for all my constraints that is trying to recover them by breaking the constraints.
This method gets call in my viewDidLoad when it detects if its an iPhone 4
- (void) addConstraints {
// removing automatic system constraints
[self.view removeConstraints:self.view.constraints];
[self.view setTranslatesAutoresizingMaskIntoConstraints:NO];
NSDictionary *views = NSDictionaryOfVariableBindings(appBackground, myCustomer, myItemDetails, myItemQuantity, myItemPrice, myNext, myBtn); // UIImageView, UITextField, UIButton
for (UIView *view in [views allValues]) {
view.translatesAutoresizingMaskIntoConstraints = NO;
}
NSDictionary *metrics = #{#"width": #210.0, #"height": #42.0, #"verticalSpacing": #34};
NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:#"V:|[appBackground]|"
options:0
metrics:nil
views:views];
constraints = [constraints arrayByAddingObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|[appBackground]|"
options:0
metrics:nil
views:views]];
constraints = [constraints arrayByAddingObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|-(85)-[myCustomer(==height)]-(verticalSpacing)-[myItemDetails(==height)]-(verticalSpacing)-[myItemQuantity(==height)]-(verticalSpacing)-[myItemPrice(==height)]-(18)-[myNext(==35)]-(71.5)-[myBtn(==50)]-(7.5)-|"
options:0
metrics:metrics
views:views]];
constraints = [constraints arrayByAddingObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|-50-[myCustomer(==width)]-|"
options:0
metrics:metrics
views:views]];
constraints = [constraints arrayByAddingObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|-50-[myItemDetails(==width)]-|"
options:0
metrics:metrics
views:views]];
constraints = [constraints arrayByAddingObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|-50-[myItemQuantity(==width)]-|"
options:0
metrics:metrics
views:views]];
constraints = [constraints arrayByAddingObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|-50-[myItemPrice(==width)]-|"
options:0
metrics:metrics
views:views]];
constraints = [constraints arrayByAddingObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|-78-[myNext(==173)]-|"
options:0
metrics:metrics
views:views]];
constraints = [constraints arrayByAddingObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|-11.5-[myBtn(==54)]-|"
options:0
metrics:metrics
views:views]];
[self.view addConstraints:constraints];
}
Error!
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:0xb8282f0 H:|-(50)-[UITextField:0xb823fc0] (Names: '|':UIView:0xb82f360 )>",
"<NSLayoutConstraint:0xb828320 H:[UITextField:0xb823fc0(210)]>",
"<NSLayoutConstraint:0xb82be10 H:[UITextField:0xb823fc0]-(NSSpace(20))-| (Names: '|':UIView:0xb82f360 )>",
"<NSLayoutConstraint:0xb82d3d0 H:|-(78)-[UIButton:0xb82ad50] (Names: '|':UIView:0xb82f360 )>",
"<NSLayoutConstraint:0xb82d420 H:[UIButton:0xb82ad50(173)]>",
"<NSLayoutConstraint:0xb82d450 H:[UIButton:0xb82ad50]-(NSSpace(20))-| (Names: '|':UIView:0xb82f360 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0xb82d450 H:[UIButton:0xb82ad50]-(NSSpace(20))-| (Names: '|':UIView:0xb82f360 )>
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.
2014-08-03 14:03:29.239 iReceipt[2886:607] 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:0xb8282f0 H:|-(50)-[UITextField:0xb823fc0] (Names: '|':UIView:0xb82f360 )>",
"<NSLayoutConstraint:0xb828320 H:[UITextField:0xb823fc0(210)]>",
"<NSLayoutConstraint:0xb82be10 H:[UITextField:0xb823fc0]-(NSSpace(20))-| (Names: '|':UIView:0xb82f360 )>",
"<NSLayoutConstraint:0xb82d480 H:|-(11.5)-[UIButton:0xb820120] (Names: '|':UIView:0xb82f360 )>",
"<NSLayoutConstraint:0xb82e390 H:[UIButton:0xb820120(54)]>",
"<NSLayoutConstraint:0xb82e3c0 H:[UIButton:0xb820120]-(NSSpace(20))-| (Names: '|':UIView:0xb82f360 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0xb82e3c0 H:[UIButton:0xb820120]-(NSSpace(20))-| (Names: '|':UIView:0xb82f360 )>
Please let me know if you guys need more information..
These three constraints:
"<NSLayoutConstraint:0xb8282f0 H:|-(50)-[UITextField:0xb823fc0] (Names: '|':UIView:0xb82f360 )>",
"<NSLayoutConstraint:0xb828320 H:[UITextField:0xb823fc0(210)]>",
"<NSLayoutConstraint:0xb82be10 H:[UITextField:0xb823fc0]-(NSSpace(20))-| (Names: '|':UIView:0xb82f360 )>",
dictate that the superview be 50 + 210 + 20 == 280 points wide.
These three constraints:
"<NSLayoutConstraint:0xb82d3d0 H:|-(78)-[UIButton:0xb82ad50] (Names: '|':UIView:0xb82f360 )>",
"<NSLayoutConstraint:0xb82d420 H:[UIButton:0xb82ad50(173)]>",
"<NSLayoutConstraint:0xb82d450 H:[UIButton:0xb82ad50]-(NSSpace(20))-| (Names: '|':UIView:0xb82f360 )>"
dictate that the same superview be 78 + 173 + 20 == 271 points wide.
Obviously, those can't both be true at the same time. You need to decide what you really want to happen here. We can't read your mind and neither can UIKit.
Usually, you don't set a width constraint on a button; you let it use its intrinsic size with appropriate priorities for content hugging and compression resistance. Also, you may not wish to set hard spacing on either side of the button. Either let that spacing vary without constraint so the button can be its intrinsic size, lower the priority of that constraint so it's optional, or make an inequality so you have a minimum spacing but not an exact spacing.
You are constraining your views too much. You must always leave for example one of leftmargin, width and rightmargin flexible, and let the autolayout engine stretch that one.
A single dash without any number means default distance, which is 20 pixels. So, if you remove your trailing constraints on
#"H:|-78-[myNext(==173)]-|"
#"H:|-11.5-[myBtn(==54)]-|"
and change them to
#"H:|-78-[myNext(==173)]"
#"H:|-11.5-[myBtn(==54)]"
the layout engine will then stretch the rightmargin of the button to make it fit the
containing view. There are of course other ways of loosening up these constraints, all depending on your design goals.
Personally, I never use the standard API:s for autolayout anymore. I use the library PureLayout, which abstracts autolayout wonderfully!

Debug constraints when setting view programmatically

I have a complex set of labels and buttons. I set everything programmatically using mainly visual format language. The UILabels are created with the following method:
-(UILabel*)createLabelWithPlaceHolder:(NSString*)placeHolder{
UILabel *provisionalLabel=[[UILabel alloc] init];
provisionalLabel =[[UILabel alloc] init];
provisionalLabel.translatesAutoresizingMaskIntoConstraints=NO;
provisionalLabel.text=placeHolder;
provisionalLabel.font=[UIFont systemFontOfSize:12.0f];
provisionalLabel.backgroundColor=[UIColor greenColor];
provisionalLabel.textAlignment=NSTextAlignmentCenter;
[provisionalLabel setContentHuggingPriority:200 forAxis:UILayoutConstraintAxisHorizontal];
[provisionalLabel setContentCompressionResistancePriority:900 forAxis:UILayoutConstraintAxisHorizontal];
return provisionalLabel;
}
and the labels are displayed according to the following VLF code:
gap=(self.vistaGris.bounds.size.width*secondRowFactor)/7;
labelWidth=(self.vistaGris.bounds.size.width*(1-secondRowFactor))/6;
gapN=[NSNumber numberWithFloat:gap];
labelWidthN=[NSNumber numberWithFloat:labelWidth];
constraints = [NSLayoutConstraint
constraintsWithVisualFormat:#"H:|-gap-[solution4(width)]-gap-[solution5(width)]-gap-[solution6(width)]-gap-[solution7(width)]-gap-[solution8(width)]-gap-[solution9(width)]-gap-|"
options:NSLayoutFormatAlignAllBaseline
metrics:#{#"gap":gapN, #"width":labelWidthN}
views:viewsDictionary];
[self.vistaGris addConstraints:constraints];
Basically what it does is to display 6 labels on the bottom of the view. With equal spaces between them and same width. The device orientation is always landscape all the time.
The code does what I want it to do and everything is displayed OK. However I got a console warning telling me that the system cannot satisfy simultaneous constraints:
2014-04-19 09:59:48.749 Concentrations[431:60b] 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:0x8d6cd70 Linees:0x8c82d70.width == UIView:0x8c41c40.width>",
"<NSLayoutConstraint:0x8d84480 H:|-(6.85714)-[UILabel:0x8d65460] (Names: '|':Linees:0x8c82d70 )>",
"<NSLayoutConstraint:0x8d844d0 H:[UILabel:0x8d65460(72)]>",
"<NSLayoutConstraint:0x8d84500 H:[UILabel:0x8d65460]-(6.85714)-[UILabel:0x8d73890]>",
"<NSLayoutConstraint:0x8d84550 H:[UILabel:0x8d73890(72)]>",
"<NSLayoutConstraint:0x8d845b0 H:[UILabel:0x8d73890]-(6.85714)-[UILabel:0x8d731b0]>",
"<NSLayoutConstraint:0x8d845e0 H:[UILabel:0x8d731b0(72)]>",
"<NSLayoutConstraint:0x8d84640 H:[UILabel:0x8d731b0]-(6.85714)-[UILabel:0x8d734e0]>",
"<NSLayoutConstraint:0x8d84690 H:[UILabel:0x8d734e0(72)]>",
"<NSLayoutConstraint:0x8d84700 H:[UILabel:0x8d734e0]-(6.85714)-[UILabel:0x8d741b0]>",
"<NSLayoutConstraint:0x8d84730 H:[UILabel:0x8d741b0(72)]>",
"<NSLayoutConstraint:0x8d847d0 H:[UILabel:0x8d741b0]-(6.85714)-[UILabel:0x8d744d0]>",
"<NSLayoutConstraint:0x8d84800 H:[UILabel:0x8d744d0(72)]>",
"<NSLayoutConstraint:0x8d84860 H:[UILabel:0x8d744d0]-(6.85714)-| (Names: '|':Linees:0x8c82d70 )>",
"<NSAutoresizingMaskLayoutConstraint:0x8c8aef0 h=--& v=--& V:[UIView:0x8c41c40(480)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x8d847d0 H:[UILabel:0x8d741b0]-(6.85714)-[UILabel:0x8d744d0]>
The thing is that I don't set constraints for these labels anywhere else on my code and this debugger warning could not be less explanatory.
The warning says that you have an NSAutoresizingMaskLayoutConstraint (it derives from the autoresize automatically translated to constraints). Probably you want to set translatesAutoresizingMaskIntoConstraints=NO not only on the labels but on the vistaGris too.

NSLayoutConstraint gives so many warnings if i simply add scrollview in it

I have stuck at problem, in my application i am adding UIScrollview programatically so i am adding NSLayoutConstraint for that but when i run this output is perfect what i want but it gives me so many warning,
So please help me to removing all this warnings,
My Code is :
- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *sc=[UIScrollView new];
sc.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:sc];
sc.backgroundColor=[UIColor purpleColor];
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(sc);
NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:#"|-5-[sc]-5-|" options:0 metrics:nil views:viewsDictionary];
[self.view addConstraints:constraints];
constraints = [NSLayoutConstraint constraintsWithVisualFormat:#"V:|-5-[sc]-5-|"
options: NSLayoutFormatAlignAllRight
metrics:nil
views:viewsDictionary];
[self.view addConstraints:constraints];
}
Unnecessary warnings:
2014-02-27 15:08:26.763 TKScroller[2580:a0b] 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:0x8da0df0 H:|-(10)-[UIView:0x8d95ef0] (Names: '|':UIScrollView:0x8d93800 )>",
"<NSAutoresizingMaskLayoutConstraint:0x8da6b10 h=--& v=--& UIView:0x8d95ef0.midX ==>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x8da0df0 H:|-(10)-[UIView:0x8d95ef0] (Names: '|':UIScrollView:0x8d93800 )>
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.
2014-02-27 15:08:26.765 TKScroller[2580:a0b] 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:0x8da15b0 V:|-(3)-[UIView:0x8d95ef0] (Names: '|':UIScrollView:0x8d93800 )>",
"<NSAutoresizingMaskLayoutConstraint:0x8da59d0 h=--& v=--& UIView:0x8d95ef0.midY ==>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x8da15b0 V:|-(3)-[UIView:0x8d95ef0] (Names: '|':UIScrollView:0x8d93800 )>
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.
2014-02-27 15:08:26.766 TKScroller[2580:a0b] 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:0x8da1580 UIView:0x8d95ef0.trailing == UIScrollView:0x8d93800.trailing - 10>",
"<_UIScrollViewAutomaticContentSizeConstraint:0x8da1200 UIScrollView:0x8d93800.contentWidth{id: 128} == 0.000000>",
"<NSAutoresizingMaskLayoutConstraint:0x8da6b10 h=--& v=--& UIView:0x8d95ef0.midX ==>",
"<NSAutoresizingMaskLayoutConstraint:0x8da6e00 h=--& v=--& H:[UIView:0x8d95ef0(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x8da1580 UIView:0x8d95ef0.trailing == UIScrollView:0x8d93800.trailing - 10>
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.
2014-02-27 15:08:26.770 TKScroller[2580:a0b] 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:0x8da15e0 UIView:0x8d95ef0.bottom == UIScrollView:0x8d93800.bottom - 3>",
"<_UIScrollViewAutomaticContentSizeConstraint:0x8da13a0 UIScrollView:0x8d93800.contentHeight{id: 133} == 0.000000>",
"<NSAutoresizingMaskLayoutConstraint:0x8da59d0 h=--& v=--& UIView:0x8d95ef0.midY ==>",
"<NSAutoresizingMaskLayoutConstraint:0x8da46f0 h=--& v=--& V:[UIView:0x8d95ef0(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x8da15e0 UIView:0x8d95ef0.bottom == UIScrollView:0x8d93800.bottom - 3>
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.
From the error messages it looks like you also need to do:
self.view.translatesAutoresizingMaskIntoConstraints = NO;
These messages:
"<NSAutoresizingMaskLayoutConstraint:0x8da6b10 h=--& v=--& UIView:0x8d95ef0.midX ==>",
"<NSAutoresizingMaskLayoutConstraint:0x8da6e00 h=--& v=--& H:[UIView:0x8d95ef0(0)]>"
Lead me to believe that the parent view (self.view) is also converting autoresizing masks to constraints.
First: try advice #Jack Cox
Second:
in line
NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:#"|-5-[sc]-5-|" options:0 metrics:nil views:viewsDictionary];
you not say what about orientation V: or H:? try relpace this line:
NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:#"H:|-5-[sc]-5-|" options:0 metrics:nil views:viewsDictionary];
MB. your constraints array rewrite? Try it:
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|-5-[sc]-5-|" options:0 metrics:nil views:viewsDictionary]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|-5-[sc]-5-|" options: NSLayoutFormatAlignAllRight metrics:nil views:viewsDictionary];

Why aren't these constraints working?

I am programatically setting the following constraints on three views inside a UIView:
UIView *view1 = ((UIViewController *)[self.viewControllers objectAtIndex:0]).view;
UIView *view2 = ((UIViewController *)[self.viewControllers objectAtIndex:1]).view;
UIView *view3 = ((UIViewController *)[self.viewControllers objectAtIndex:2]).view;
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(view1, view2, view3);
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|-0-[view1(==320)]-0-[view2(==320)]-0-[view3(==320)]|" options:0 metrics:0 views:viewsDictionary]];
My intention is that each view is 320px wide, sitting flush against one-another with no gap, and view one up against the left edge of the containing UIView.
However, when compiled, the views are laid out on-top of one-another and I get the following in the console:
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:0x211811c0 H:|-(0)-[UIView:0xc683790] (Names: '|':UIView:0xc683320 )>",
"<NSAutoresizingMaskLayoutConstraint:0x21179820 h=-&- v=-&- UIView:0xc683790.midX == UIView:0xc683320.midX - 340>",
"<NSLayoutConstraint:0x211793d0 H:[UIView:0xc6a50c0]-(0)-| (Names: '|':UIView:0xc683320 )>",
"<NSLayoutConstraint:0x21179390 H:[UIView:0xc6a50c0(320)]>",
"<NSLayoutConstraint:0x21179350 H:[UIView:0xc6a05f0]-(0)-[UIView:0xc6a50c0]>",
"<NSLayoutConstraint:0x211563d0 H:[UIView:0xc6a05f0(320)]>",
"<NSLayoutConstraint:0x21156390 H:[UIView:0xc683790]-(0)-[UIView:0xc6a05f0]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x21179350 H:[UIView:0xc6a05f0]-(0)-[UIView:0xc6a50c0]>
Try setting
[view setTranslatesAutoresizingMaskIntoConstraints:NO];
for all of your views, it usually is enough to solve this kind of problem.

Resources