title: Swift Add UIViewController or UIView inside UITableViewCell programatically
body: <p>I have a custom subclass of a UIViewController created with the swift file and the Xib.</p>
  
  <p>I want to reuse this subclass in multiple places (because is complex), so i don't want to make an other subclass of UITableViewCell or UICollectionViewCell and implement the same behaviour. </p>
  
  <p>My ViewController is also expandable so i don't have a single size but is determined by the visibility of it's components ( i have some constraints that are reduced to 0 when collapsed or to it's normal size when expanded ) </p>
  
  <p>What's the best way to add this UIViewController (or it's view) to a cell (table or collection ) only by subclassing the cell? </p>
  
  <p>Simply by adding the view of the ViewController to contentView ( of a cell) and setting it's frame doesn't work, the view is displayed one on each other and with the origin too upward.</p>
  
  <p>Update:</p>
  
  <p>Example:</p>
  
  <p>MyViewController:</p>
  
  <pre><code>class MyViewController: UIViewController
  {
  // has the view property 
  }
  </code></pre>
  
  <p>MyCell</p>
  
  <pre><code>class MyCell: UITableViewCell 
  {
  
  var myViewController:  MyViewController!
     override func awakeFromNib()
    {
        myViewController = MyViewController()
         self.contentView.addSubview(myViewController.view)
       //what to do next to fit the myViewController inside contentView, 
       //myViewController.view is bigger , 
       //and make the cell to follow the myViewController.view size
  
    }
  
  }
  </code></pre>