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.
Related
I have a simple UICollectionVewController with one prototype cell. In the cell all I have is a UILabel.
I have size classes and auto layout selected. I have set a constraint for
top (Top Space to cell): = 100
Height >= 17
Trailing space to Cell = 0
Leading Space to Cell = 0
In this configuration it works fine. However I want a left and right margin on the cell, so I changed the Leading and Trailing space to 10.
Although this works, I get the following 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:0x1740907c0 H:[UILabel:0x14de1a380'This is a test to see wha...']-(10)-| (Names: '|':UIView:0x14de1a270 )>",
"<NSLayoutConstraint:0x174090810 H:|-(10)-[UILabel:0x14de1a380'This is a test to see wha...'] (Names: '|':UIView:0x14de1a270 )>",
"<NSAutoresizingMaskLayoutConstraint:0x174090d10 h=--& v=--& H:[UIView:0x14de1a270(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1740907c0 H:[UILabel:0x14de1a380'This is a test to see wha...']-(10)-| (Names: '|':UIView:0x14de1a270 )>
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.
If I set the leading space to 10 and remove the training space and set a width constraint, I do not get the error.
However, the width of the cell is variable so I can't set the width.
I can work around it, by creating an outlet to the width constraint and doing this:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
CGRect colViewSize = collectionView.bounds;
int width = colViewSize.size.width;
width -= 28; // 10px either size and 8px in middle
width = width/2;
width -=14; // margin of 7 (x 2)
cell.labelconstraintWidth.constant = width;
return cell;
however this seems such a hack.
Does anyone have any clue what is happening here.
Simply put, your view resizes, and when it does, the constraints of 10 leading and 10 trailing space can't be satisfied because your view's width is less than 20.
Solution? Either put a percentual label margins / width to the superview or make the the margins zero, if you don't want to think about it.
However, if you have a encapsulated logic that calculates the cell width, you can easily add margin constraints from code.
EDIT:
You might have an autolayout constraint that's 50%, but that's not the issue here. You got an AutoResizingMaskLayoutConstraint that's affecting you view's width.
In order to create a percentual margin in storyboard, do:
1) Select your view in the view hierarchy
2) Hold CTRL and drag to your superview(or the root view that's taking the full bounds of the superview)
3) Select Horizontal Spacing
4) Select your view and double click on the Horizontal Spacing constraint
5) In the size inspector select:
First item: YourView.Leading
Relation: Equal
Second item: YourSuperview.Trailing
Constant: 0
Priority: 1000
Multiplier: (your margin percentage)
As #Bamsworld said, you should double check for AutoResizing masks. They might be conflicting with your AutoLayout constraints.
The error tells you one or more constraints is not needed and lists one of the constraints as NSAutoresizingMaskLayoutConstraint. It would appear that there is a conflict with auto-layout and autoresizingmasks. I suggest to use one or the other.
Try removing the autoresize-constraint by calling setTranslatesAutoresizingMaskIntoConstraints on the view and pass in NO. Also set the autoresizingMask property of the view to UIViewAutoresizingNone (just to be sure).
Before iOS 8 (and it's SDK) I did auto height of UITableViewCell using this delegate method:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (!_prototypeCell)
{
_prototypeCell = [tableView dequeueReusableCellWithIdentifier:#"MyShowIdentifier"];
}
EventShow *show = self.myShows[indexPath.row];
self.prototypeCell.categoryNameLabel.text = show.event.category.name;
self.prototypeCell.eventNameLabel.text = show.event.title;
[self.prototypeCell layoutIfNeeded];
CGSize size = [self.prototypeCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return size.height + 1.0f;
}
My cell has two labels, one on top of the other with autolayout constraints telling the labels to grow vertically as much as the want. Everything worked fine.
After iOS 8 came, I get an "Unable to simultaneously satisfy constraints" error ONLY THE FIRST TIME THE METHOD systemLayoutSizeFittingSize: IS EXECUTED. The delegate method is called 3 times. This is the detail of the error:
(
"<NSLayoutConstraint:0x7fd1e8ebce30 H:|-(5)-[UILabel:0x7fd1eb0e00a0'Cine'] (Names: '|':UITableViewCellContentView:0x7fd1eb0c0210 )>",
"<NSLayoutConstraint:0x7fd1eb06b120 H:[UILabel:0x7fd1eb0e00a0'Cine']-(5)-| (Names: '|':UITableViewCellContentView:0x7fd1eb0c0210 )>",
"<NSLayoutConstraint:0x7fd1e8e7be50 'UIView-Encapsulated-Layout-Height' H:[UITableViewCellContentView:0x7fd1eb0c0210(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fd1eb06b120 H:[UILabel:0x7fd1eb0e00a0'Cine']-(5)-| (Names: '|':UITableViewCellContentView:0x7fd1eb0c0210 )>
There is a new constraint there called "UIView-Encapsulated-Layout-Height" with is set to zero. I don't now what that is, but I'm sure it should be > 0.
The auto height still works in iOS 8, but it throws this error that i can't fix.
Any ideas? Thanks a lot!
The error you are getting is for width of label as you had set specific width and you also set leading and trailing constraint. So what is happening here is to label is breaking leading,trailing or width constraint to satisfy trailing constraint of label.
But to satisfy your constraint for trailing it will break width constraint.
What you need to do here is just set leading,top, trailing and bottom constraint to both the label. Also you need to set vertical spacing between those label and no need to set height and width constraints to both label.
Also in attribute inspector you set lines = 0, Line Breaks = Word Wrap.
you also need to set “self.tableView.rowHeight = UITableViewAutomaticDimension;” in viewDidLoad.
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.
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.
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.
I have the following simple test code in my controller:
- (void)loadView
{
UIView *view = [UIView new];
[self setView:view];
UILabel *label = [UILabel new];
[label setText:#"Hello World!"];
[view addSubview:label];
[view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"|-[label]"
options:0 metrics:nil views:NSDictionaryOfVariableBindings(label)]];
}
The code fails with the following exception and I can't figure out why. Any help would be greatly appreciated:
2013-04-15 14:15:47.880 libmarkup-test[1072:c07] 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:0x753eb60 H:|-(NSSpace(20))-[UILabel:0x7536b60] (Names: '|':UIView:0x75376a0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x712a2c0 h=--& v=--& UILabel:0x7536b60.midX ==>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x753eb60 H:|-(NSSpace(20))-[UILabel:0x7536b60] (Names: '|':UIView:0x75376a0 )>
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.
The "unable to simultaneously satisfy constraints" message is especially confusing since, as far as I can tell, I'm only specifying one constraint.
It looks like you forgot to set translatesAutoresizingMaskIntoConstraints on the UILabel. By default it will be YES. So the autoresizing mask on that label are translated to additional constraints, which are then conflicting with the one you specified.
Adding this should fix the constraint issue:
label.translatesAutoresizingMaskIntoConstraints = NO;
You should probably think about a vertical constraints on that label as well.
please adjust the constraint priority( default is 1000) and hugging priority(default is 250)