title: Loading tablecell content from custom view
body: <p>I am new to <code>swift</code> and below is the problem that I face
  I have a tableview and one of the cell is customCell which loads custom view. No crashes but the constraints and background color for table cell are not displaying. <strong>Please refer to code below</strong></p>
  
  <pre><code>class ViewController: UIViewController, UITableViewDataSource {
  
  
      let data = ["Apple", "Banana", "Orange", "Grape", "Banana", "Orange", "Grape", "Banana", "Orange", "Grape", "Banana", "Orange", "Grape", "Banana", "Orange", "Grape", "Banana", "Orange", "Grape", "Banana", "Orange", "Grape", "Banana", "Orange", "Grape", "Banana", "Orange", "Grape", "Banana", "Orange", "Grape"]
      @IBOutlet weak var tableView: UITableView!
  
      @IBOutlet weak var customView: CustomView!
      override func viewDidLoad() {
          super.viewDidLoad()
          customView.myLabel.text = "Hey hey"
          customView.backgroundColor = UIColor.green
          tableView.dataSource = self
          tableView.register(UINib(nibName: "CustomTableViewCell", bundle: nil), forCellReuseIdentifier: "customCell")
          tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
          tableView.tableFooterView = UIView()
      }
  
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          data.count
      }
  
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          if indexPath.row == 3 {
              guard let cell = tableView.dequeueReusableCell(withIdentifier: "customCell", for: indexPath) as? CustomTableViewCell else { return UITableViewCell()}
  
  //            cell.layoutSubviews()
  //            cell.layoutIfNeeded()
              return cell
          } else {
              let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
              cell.textLabel?.text = data[indexPath.row]
              return cell
          }
  
  
      }
  }
  
  
  Custom View:
  class CustomView: UIView {
  
      @IBOutlet var contentView: UIView!
      @IBOutlet weak var myLabel: UILabel!
  
      let kCONTENT_XIB_NAME = "CustomView"
      override init(frame: CGRect) {
          super.init(frame: frame)
          commonInit()
      }
  
      required init?(coder: NSCoder) {
          super.init(coder: coder)
          commonInit()
      }
  
      private func commonInit() {
          Bundle.main.loadNibNamed(kCONTENT_XIB_NAME, owner: self, options: nil)
          contentView.fixInView(self)
      }
  
  }
  
  extension UIView
  {
      func fixInView(_ container: UIView!) -&gt; Void{
          self.translatesAutoresizingMaskIntoConstraints = false;
          self.frame = container.frame;
          container.addSubview(self);
          NSLayoutConstraint(item: self, attribute: .leading, relatedBy: .equal, toItem: container, attribute: .leading, multiplier: 1.0, constant: 0).isActive = true
          NSLayoutConstraint(item: self, attribute: .trailing, relatedBy: .equal, toItem: container, attribute: .trailing, multiplier: 1.0, constant: 0).isActive = true
          NSLayoutConstraint(item: self, attribute: .top, relatedBy: .equal, toItem: container, attribute: .top, multiplier: 1.0, constant: 0).isActive = true
          NSLayoutConstraint(item: self, attribute: .bottom, relatedBy: .equal, toItem: container, attribute: .bottom, multiplier: 1.0, constant: 0).isActive = true
      }
  }
  
  Custom Tablecell:
  class CustomTableViewCell: UITableViewCell {
  
      @IBOutlet weak var cellContentView: CustomView!
      override func awakeFromNib() {
          super.awakeFromNib()
          // Initialization code
          cellContentView.backgroundColor = UIColor.blue
      }
  
      override func setSelected(_ selected: Bool, animated: Bool) {
          super.setSelected(selected, animated: animated)
  
          // Configure the view for the selected state
      }
  
  }
  
  </code></pre>
  
  <p>Below is the storyboard structure 
  <a href="https://i.stack.imgur.com/AvkkX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AvkkX.png" alt="enter image description here"></a></p>
  
  <p>When I run the app below is the screenshot how it displays
  <a href="https://i.stack.imgur.com/2d3ZF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2d3ZF.png" alt="enter image description here"></a></p>
  
  <p><strong>Issue 1</strong>: Row 3 is customview whose background should be blue as set in Custom cell class</p>
  
  <p><strong>Issue 2</strong>: In my viewcontroller, even after setting background color as green why is it not displaying that color. "Orange" is used in storyboard while creating view</p>
  
  <p><strong>Issue 3</strong>: If I have more dynamic controls in view, how the cell height be set. </p>
  
  <p>Please advice. I'm struck here</p>