Ambiguous layout with dynamic tableView height

后端 未结 2 801
旧时难觅i
旧时难觅i 2021-01-22 17:35

I have a viewController and I want to have two 1 tableView and 1 childViewController inside it.

  • tableView is non-scrollable with dynamic cell heights. (I\'m using
2条回答
  •  春和景丽
    2021-01-22 18:15

    I suggest subclassing UITableView like this:

    class AutomaticHeightTableView: UITableView {
    
      override var intrinsicContentSize: CGSize {
        return contentSize
      }
    
      override func reloadData() {
        super.reloadData()
        invalidateIntrinsicContentSize()
      }
    }
    

    Then in Interface Builder set AutomaticHeightTableView as the class to your table view and the table will try to size itself to fit the content. It will follow any other constraints you placed so make sure the constraints allow it to grow freely.

提交回复
热议问题