I'm trying to use the usual method of removing a label and have autolayout adjust everything. How to change label constraints during runtime. However, I am doing it in a UITableView header.
When I set the height constraint of one of the labels:
self.labelAHeight.constant = 0;
The result is:
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:0xb0faad0 V:[UILabel:0xb0fa830(0)]>",
"<NSLayoutConstraint:0xb0772a0 V:[UILabel:0xb077300(58)]>",
"<NSLayoutConstraint:0xb076cc0 V:|-(0)-[UILabel:0xb0fa830] (Names: '|':UIView:0xb077660 )>",
"<NSLayoutConstraint:0xb076c90 V:[UILabel:0xb077300]-(0)-| (Names: '|':UIView:0xb077660 )>",
"<NSLayoutConstraint:0xb076c00 V:[UILabel:0xb0fa830]-(0)-[UILabel:0xb077300]>",
"<NSAutoresizingMaskLayoutConstraint:0xb06f030 h=--& v=--& V:[UIView:0xb077660(119)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0xb0772a0 V:[UILabel:0xb077300(58)]>
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.
I have tried [self.labelA setTranslatesAutoresizingMaskIntoConstraints:NO]
which does not help.
I have tried [self.table.tableHeaderView setTranslatesAutoresizingMaskIntoConstraints:NO]
which crashes with *** Assertion failure in -[UITableView layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2935.137/UIView.m:8794
. Possibly, I'm doing this in the wrong place (just before setting the constraint constant).
It doesn't seem to matter where the constraint change occurs, e.g. viewDidLoad
, or a button handler.
It appears as though the header wants to be a certain height (<NSAutoresizingMaskLayoutConstraint:0xb06f030 h=--& v=--& V:[UIView:0xb077660(119)]>
based on its contents) and autolayout gets very unhappy if the contents are changed.
Can anyone help debug this or suggest how to solve it? (I've tried Instruments but was baffled by all the constraints being added and removed...)