I’m trying to get rid of constraint problems appearing in my UITableView
with custom cells. The height of the rows is set to automatic, and is defined by constraints.
For example, I have a cell containing only a UITextField
that has a height set (44.0) and that is sticking at top and bottom.
When the separators are deactivated on my UITableView
, there is no problem. Therefore, when I activate them, I have the following warning in my console:
[LayoutConstraints] 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.
(
"<NSLayoutConstraint:0x28333a670 UITextField:0x103655390.height == 44 (active)>",
"<NSLayoutConstraint:0x28333a7b0 V:[UITextField:0x103655390]-(0)-| (active, names: '|':UITableViewCellContentView:0x103654e20 )>",
"<NSLayoutConstraint:0x28333a990 V:|-(0)-[UITextField:0x103655390] (active, names: '|':UITableViewCellContentView:0x103654e20 )>",
"<NSLayoutConstraint:0x28333ba20 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x103654e20.height == 44.3333 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x28333a670 UITextField:0x103655390.height == 44 (active)>
It seems that the system adds the UIView-Encapsulated-Layout-Height
constraint to set the height and it contains the size of the separator (0.33). It conflicts with the desired height, and it overrides my constraints.
This is a problem when I try to update the height of the cell by changing the height of the UITextField
, for example.
Is there any way to remove those annoying warnings?
Edit
Thank to you I found a way to get rid of the warning and to get animated height transformations at runtime:
1: set the bottom constraint priority ≤ 999,
2: after constraint change, call
tableView.beginUpdates()
tableView.endUpdates()
This will recalculate the height of the row, and UITableView
automatically animates the change.
BUT the animation is glitchy…
If you let the bottom constraint priority at 1000, the animation is smooth, but the warning appears every time the constraint changes.
If you set the bottom constraint priority at 999 for example, warnings are gone, but the content of the cell jumps from one position to another…
I will stay with the warnings for the moment, and hope that Apple fix this in the future versions.
Thank you for your answers!