uitableviewcell with dynamic height child view controller

102 Views Asked by At

I have a custom uitableviewcell that has an embeded child view controller. This child view controller uses autolayout and contains another uitableview. I'm trying to render the cell so that the child view controller's tableview is exactly the height of the contents.

  • I know that you can do that by setting tableview height constraint equal to the contentsize.height
  • but since it's in a tableviewcell, there is already an encapsulated height calculated. How do I force the cell to resize with the new child view controller's uitableview updated height constraint?
1

There are 1 best solutions below

0
Ishteyaque Ahmad On

Try to Use AutoHeight TableView inside your custom cell instead of child View Controller. Set scrolling and jumping property to false of AutoHeight Table.

final class AutoHeightTableView: UITableView {
    override var intrinsicContentSize: CGSize {
        self.layoutIfNeeded()
        return self.contentSize
    }
    override var contentSize: CGSize {
        didSet{
            UIView.performWithoutAnimation {
                self.invalidateIntrinsicContentSize()
            }
        }
    }
}