Reputation: 593
I'm having some troubles with one my constrains in code This the error i'm getting
2017-04-08 18:14:36.798 App[465:89996] 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. ("<_UILayoutSupportConstraint:0x16eb9f00 V:[_UILayoutGuide:0x16d0cb40(64)]>",
"<_UILayoutSupportConstraint:0x16eb2de0 V:|-(0)-[_UILayoutGuide:0x16d0cb40] (Names: '|':UIView:0x16d32990 )>",
"<NSLayoutConstraint:0x16d06120 V:[_UILayoutGuide:0x16d0cb40]-(0)-[UITableView:0x17ba6e00]>",
"<NSLayoutConstraint:0x16f45f90 V:|-(63.2)-[UITableView:0x17ba6e00] (Names: '|':UIView:0x16d32990 )>" ) Will attempt to recover by breaking constraint
This is the code that i have for the constrain: Viewdidload
let aka = (self.navigationController?.navigationBar.frame.size.height)! + 19.2
holamama = tableView.topAnchor.constraint(equalTo: view.topAnchor, constant: aka)
//This is out of any methods...
var holamama = NSLayoutConstraint()
In my UIBUtton:
NSLayoutConstraint.activate([holamama])
Other UIButton:
NSLayoutConstraint.deactivate([holamama])
So what can i do? Thanks!
Upvotes: 0
Views: 28
Reputation: 593
I solved doing this: First, i connected an IBOutlet of my tableview's top constrain
@IBOutlet var constrainTop: NSLayoutConstraint!
Then, when i press the button, this happen:
let aka = (self.navigationController?.navigationBar.frame.size.height)! + 1.0
constrainTop.constant = aka
And when i press the other button, this happen:
constrainTop.constant = 0
I just had to modified the constant of my tableView
Upvotes: 0
Reputation: 11221
Because you haven't specified the behavior you want, I can't suggest a better way to do it. However, I can help explain what's going wrong.
The error message is pretty helpful in this case. It lists four constraints, suggesting that at least one is erroneous.
"<_UILayoutSupportConstraint:0x16eb9f00 V:[_UILayoutGuide:0x16d0cb40(64)]>",
"<_UILayoutSupportConstraint:0x16eb2de0 V:|-(0)-[_UILayoutGuide:0x16d0cb40] (Names: '|':UIView:0x16d32990 )>",
These two constraints are of type _UILayoutSupportConstraint
, which means in this case that you didn't create them. Together they define the position of the topLayoutGuide
. Thus, they are likely not the problem.
"<NSLayoutConstraint:0x16d06120 V:[_UILayoutGuide:0x16d0cb40]-(0)-[UITableView:0x17ba6e00]>",
This constraint says "the top of the of the UITableView
is touching the bottom of the _UILayoutGuide
.
"<NSLayoutConstraint:0x16f45f90 V:|-(63.2)-[UITableView:0x17ba6e00] (Names: '|':UIView:0x16d32990 )>"
This is your explicitly created constraint. It says "the top of the UITableView
is 63.2 points below the top of its superview.
Do you see why Auto Layout is complaining? You're telling it that the top of the UITableView
must touching the bottom of the _UILayoutGuide
, 64 points below the top of the screen, and must also be 63.2 points below the top of the screen. Those two demands are incompatible, hence the error.
Upvotes: 1