title: AutoResizing header & Cell in Programmatically UITableView
body: <p>I have UIViewTable created programmatically
  I customised the headers and cell look via Extension.
  All I need is to make the large amount of texts displayed in header/cell to be viewed with:</p>
  
  <blockquote>
  <pre><code>lineBreakMode = NSLineBreakMode.byWordWrapping // enable multi line
  numberOfLines = 0 // for Automatic size
  </code></pre>
  </blockquote>
  
  <p>I nearly used everything, but nothing is working.</p>
  
  <p>I used:</p>
  
  <blockquote>
  <pre><code>self.tableView.estimatedRowHeight = 200.0
  self.tableView.rowHeight = UITableView.automaticDimension
  </code></pre>
  </blockquote>
  
  <p>I put: </p>
  
  <blockquote>
  <pre><code>override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -&gt; CGFloat {
      return 100
      }
  </code></pre>
  </blockquote>
  
  <p>I also did:</p>
  
  <blockquote>
  <pre><code>override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {
          return UITableView.automaticDimension
      }
  </code></pre>
  </blockquote>
  
  <p>Nothing seems to work</p>
  
  <p>here is my Extension:</p>
  
  <blockquote>
    <p>extension indexController {</p>
  
  <pre><code>    override func numberOfSections(in tableView: UITableView) -&gt; Int {
          return sections.count
  
      }
  
      override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          let subDatas = sections[section].sub_catigories // [1]
          return subDatas?.count ?? 0
  
  
      }
  
  
  
      override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
          let currentSection = sections[indexPath.section]
          let currentSubdata = currentSection.sub_catigories?[indexPath.row]
          //print(currentSubdata!.id)
  
  
          let vc = indexControllerTwo()
          vc.catNumber = currentSubdata!.id
          vc.sectionTitle = currentSubdata?.name
          navigationController?.pushViewController(vc, animated: true)
  
      }
  
  
      override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell = tableView.dequeueReusableCell(withIdentifier: "cellid", for: indexPath)
  
          // [2]
          let currentSection = sections[indexPath.section]
          let currentSubdata = currentSection.sub_catigories![indexPath.row]
  
          // use listCell
          guard let titleCell = cell as? listCell else {
              return cell
          }
  
          titleCell.titleLabel.text = currentSubdata.name
          titleCell.listCount.text = "\(currentSubdata.number_of_subcatigories ?? 0)"
  
  //        titleCell.titleLabel.numberOfLines = 3
  //        titleCell.titleLabel.lineBreakMode = NSLineBreakMode.byWordWrapping
  //        titleCell.titleLabel.baselineAdjustment = .alignCenters
  //        titleCell.titleLabel.adjustsFontSizeToFitWidth = true
  
  
  //        self.tableView.estimatedRowHeight = 200.0
  //        self.tableView.rowHeight = UITableView.automaticDimension
  
  
  
          cell.layer.backgroundColor = UIColor.clear.cgColor
  
          return cell
      }
  </code></pre>
  </blockquote>
  
  <p>Please note that: listCell is just for customization and constraint
  and here it is:</p>
  
  <blockquote>
  <pre><code>import UIKit
  
  class listCell: UITableViewCell {
  
      var safeArea: UILayoutGuide!
      let imageCell = UIImageView()
      let titleLabel = UILabel()
      let subTitleLabel = UILabel()
      let listCount = UILabel()
  
  
  
      override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
          super.init(style: style, reuseIdentifier: reuseIdentifier)
          setupView()
      }
  
      required init?(coder: NSCoder) {
          fatalError("init(coder:) has not been implemented")
      }
  
      func setupView(){
          safeArea = layoutMarginsGuide
          setupTitleLabel()
          setupListCount()
  
      }
  
  
  
      func setupTitleLabel(){
          addSubview(titleLabel)
          titleLabel.translatesAutoresizingMaskIntoConstraints = false
          NSLayoutConstraint.activate([
              titleLabel.leadingAnchor.constraint(equalTo: safeArea.leadingAnchor),
              titleLabel.topAnchor.constraint(equalTo: topAnchor, constant: 7)
              ])
  
  
          titleLabel.font = UIFont(name: "verdana-Bold", size: 16)
  
  
  
      }
  
  
  
      func setupListCount(){
          addSubview(listCount)
          listCount.translatesAutoresizingMaskIntoConstraints = false
          NSLayoutConstraint.activate([
              listCount.leadingAnchor.constraint(equalTo: safeArea.trailingAnchor, constant: -30),
              listCount.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: -11)
              ])
  
  
          listCount.font = UIFont(name: "verdana", size: 10)
  
      }
  
  
  
  
  }
  </code></pre>
  </blockquote>
  
  <p>Please help me make the header and cell text field to be auto resizing.
  thanks for your time. </p>