title: Programmatic NSLayoutConstraint not working expectedly in UITableViewCell class
body: <p>I'm trying to build a chat application with variable row height. Here's what I put in the UIViewController class's viewDidLoad() holding the UITableView for the purpose:</p>
  
  <pre><code>tblMessages.estimatedRowHeight = 80.0
  tblMessages.rowHeight = UITableViewAutomaticDimension
  </code></pre>
  
  <p>Next I've created a custom UITableViewCell class with following codes:</p>
  
  <pre><code>    class MessageTableViewCell: UITableViewCell
  {
      var messageBG = UIView()
      var textMessage = UILabel()
  
      override func awakeFromNib()
      {
          super.awakeFromNib()
  
          messageBG.backgroundColor = UIColor.grayColor()
          messageBG.frame = CGRectMake(0, 0, 10, 40)
          messageBG.layer.cornerRadius = 20
  
          self.textMessage.numberOfLines = 0
          self.textMessage.lineBreakMode = NSLineBreakMode.ByWordWrapping
  
          addSubview(messageBG)
          addSubview(textMessage)
      }
  
      override func drawRect(rect: CGRect)
      {
          super.drawRect(rect)
          refreshView()
      }
  
      override func setSelected(selected: Bool, animated: Bool)
      {
          super.setSelected(selected, animated: animated)
      }
  
      func refreshView()
      {
          //NSLayoutConstraint.deactivateConstraints(self.constraints())
  
          textMessage.setTranslatesAutoresizingMaskIntoConstraints(false)
          self.addConstraint(NSLayoutConstraint(item: textMessage, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0))
          self.addConstraint(NSLayoutConstraint(item: textMessage, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Leading, multiplier: 1, constant: 20))
          self.addConstraint(NSLayoutConstraint(item: textMessage, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Trailing, multiplier: 1, constant: -50))
          self.addConstraint(NSLayoutConstraint(item: textMessage, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 20))
          self.addConstraint(NSLayoutConstraint(item: textMessage, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 19))
  
          self.messageBG.setTranslatesAutoresizingMaskIntoConstraints(false)
          self.addConstraint(NSLayoutConstraint(item: self.messageBG, attribute: NSLayoutAttribute.CenterY, relatedBy: .Equal, toItem: self, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0))
          self.addConstraint(NSLayoutConstraint(item: self.messageBG, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Leading, multiplier: 1, constant: 8))
          self.addConstraint(NSLayoutConstraint(item: self.messageBG, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Trailing, multiplier: 1, constant: -49))
          self.addConstraint(NSLayoutConstraint(item: self.messageBG, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 6))
          self.addConstraint(NSLayoutConstraint(item: self.messageBG, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 6))
      }
  }
  </code></pre>
  
  <p>In above, I'm adding a coloured background (UIView) and a multi-line UILabel. When passing a long text to a row cell, I got this when application starts: <a href="http://postimg.org/image/8xvcshkfh/" rel="nofollow">http://postimg.org/image/8xvcshkfh/</a></p>
  
  <p>When I rotate the view in simulator, then I have this but yet with wrong dimension/constraints: <a href="http://postimg.org/image/oyl1yyi3h/" rel="nofollow">http://postimg.org/image/oyl1yyi3h/</a></p>
  
  <p>Can somebody help me what I'm doing wrong?</p>