title: autolayout constraints not working correctly when adding them programmatically
body: <p>this is my view</p>
  
  <p><a href="https://i.stack.imgur.com/3j2zT.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3j2zT.jpg" alt="enter image description here"></a></p>
  
  <p>the black area is a view, called <code>containerView</code> that has the following constrains</p>
  
  <p><a href="https://i.stack.imgur.com/hnshe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hnshe.png" alt="enter image description here"></a></p>
  
  <p>i want to add a uitableView to it dyrnamically, i did this:</p>
  
  <pre><code> func setConstraintsForTableView(tableView: UITableView){
  
          self.containerView.addSubview(tableView)
  
          let bottomConstraint = tableView.bottomAnchor.constraintEqualToAnchor(self.containerView.bottomAnchor)
          let leftConstraint = tableView.leftAnchor.constraintEqualToAnchor(self.containerView.leftAnchor)
          let rightConstraint = tableView.rightAnchor.constraintEqualToAnchor(self.containerView.rightAnchor)
          let topConstraint = tableView.topAnchor.constraintEqualToAnchor(self.containerView.topAnchor)
          self.containerView.translatesAutoresizingMaskIntoConstraints = false
          NSLayoutConstraint.activateConstraints([bottomConstraint, leftConstraint, rightConstraint, topConstraint])
  
          self.containerView.layoutIfNeeded()
  
      }
  </code></pre>
  
  <p>but i got this in the log:</p>
  
  <pre><code>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) 
  (
      "&lt;NSAutoresizingMaskLayoutConstraint:0x7fe8c9c2ddb0 h=--&amp; v=--&amp; UITableView:0x7fe8cd05c200.midX == + 120&gt;",
      "&lt;NSLayoutConstraint:0x7fe8c9e97340 UIView:0x7fe8c9e8aeb0.trailingMargin == UIView:0x7fe8cb304490.trailing&gt;",
      "&lt;NSLayoutConstraint:0x7fe8c9e97390 UIView:0x7fe8cb304490.leading == UIView:0x7fe8c9e8aeb0.leadingMargin&gt;",
      "&lt;NSLayoutConstraint:0x7fe8c9c2cf70 H:|-(0)-[UITableView:0x7fe8cd05c200](LTR)   (Names: '|':UIView:0x7fe8cb304490 )&gt;",
      "&lt;NSLayoutConstraint:0x7fe8c9c2d0c0 UITableView:0x7fe8cd05c200.right == UIView:0x7fe8cb304490.right&gt;",
      "&lt;NSLayoutConstraint:0x7fe8cb104c40 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fe8c9e8aeb0(375)]&gt;"
  )
  
  Will attempt to recover by breaking constraint 
  &lt;NSLayoutConstraint:0x7fe8c9c2d0c0 UITableView:0x7fe8cd05c200.right == UIView:0x7fe8cb304490.right&gt;
  
  Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
  The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in &lt;UIKit/UIView.h&gt; may also be helpful.
  2015-12-19 22:12:16.201 GrabATable[2419:218311] 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) 
  (
      "&lt;_UILayoutSupportConstraint:0x7fe8cb036c70 V:[_UILayoutGuide:0x7fe8c9e956a0(20)]&gt;",
      "&lt;_UILayoutSupportConstraint:0x7fe8cb0365c0 V:|-(0)-[_UILayoutGuide:0x7fe8c9e956a0]   (Names: '|':UIView:0x7fe8c9e8aeb0 )&gt;",
      "&lt;_UILayoutSupportConstraint:0x7fe8cb0363d0 V:[_UILayoutGuide:0x7fe8c9e96410(0)]&gt;",
      "&lt;_UILayoutSupportConstraint:0x7fe8cb018490 _UILayoutGuide:0x7fe8c9e96410.bottom == UIView:0x7fe8c9e8aeb0.bottom&gt;",
      "&lt;NSAutoresizingMaskLayoutConstraint:0x7fe8c9c2de50 h=--&amp; v=--&amp; UITableView:0x7fe8cd05c200.midY == + 64&gt;",
      "&lt;NSLayoutConstraint:0x7fe8c9e97070 UIImageView:0x7fe8c9e8a160.height == 0.33*UIView:0x7fe8c9e8aeb0.height&gt;",
      "&lt;NSLayoutConstraint:0x7fe8c9e97110 V:[_UILayoutGuide:0x7fe8c9e956a0]-(0)-[UIImageView:0x7fe8c9e8a160]&gt;",
      "&lt;NSLayoutConstraint:0x7fe8c9e972f0 V:[UIImageView:0x7fe8c9e8a160]-(20)-[UIView:0x7fe8cb304490]&gt;",
      "&lt;NSLayoutConstraint:0x7fe8c9e973e0 V:[UIView:0x7fe8cb304490]-(0)-[_UILayoutGuide:0x7fe8c9e96410]&gt;",
      "&lt;NSLayoutConstraint:0x7fe8c9c2cc50 UITableView:0x7fe8cd05c200.bottom == UIView:0x7fe8cb304490.bottom&gt;",
      "&lt;NSLayoutConstraint:0x7fe8c9c2d210 V:|-(0)-[UITableView:0x7fe8cd05c200]   (Names: '|':UIView:0x7fe8cb304490 )&gt;",
      "&lt;NSLayoutConstraint:0x7fe8cb104c90 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7fe8c9e8aeb0(667)]&gt;"
  )
  
  Will attempt to recover by breaking constraint 
  &lt;NSLayoutConstraint:0x7fe8c9c2cc50 UITableView:0x7fe8cd05c200.bottom == UIView:0x7fe8cb304490.bottom&gt;
  
  Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
  The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in &lt;UIKit/UIView.h&gt; may also be helpful.
  </code></pre>