-2

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?
  • Its a bad idea to add view controller inside the table view cell, still if you are making then the `UITableViewController must have static Cells` – vignesh Feb 06 '23 at 10:25
  • The problem is timing... "Main Table View" lays out its cells... then "cell" loads a child VC with a table view, which *then* tries to set its own height. This is a common problem with dynamic sizing table views (and collection views) embedded in cells. This is why using multiple sections is a better idea than trying to embed table views in cells. If you show what your goal is supposed to look like, we might be able to help you with your approach. – DonMag Feb 06 '23 at 15:52

1 Answers1

0

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()
            }
        }
    }
}