set dynamic height for the parent child tableView Swift
Asked Answered
T

0

0

I have created nested tableView approach, In a view controller I set tableView and then nested tableView for the Cell. So its like Parent tableView and Child tableView.

For adjusting content height tableView row height autoDimension I have created custom class for it and override intrinsicContentSize but I am still getting scrollbar in nested tableview. ContentSize updating but row height not adjusting. I have already set automatic row height for both the parent and child table view.

  • How can I avoid this scrollbar when my content expand it should auto set tableView row height?.

Attaching GitHub code reference and images as well. https://github.com/MasamMahmood/autoHeightTableView

Custom Class Code:

class MyOwnTableView: UITableView {
    override var intrinsicContentSize: CGSize {
        self.layoutIfNeeded()
        print("ContentSizee \(contentSize)")
        return self.contentSize
    }

    override var contentSize: CGSize {
        didSet{
            self.invalidateIntrinsicContentSize()
        }
    }

    override func reloadData() {
        super.reloadData()
        self.invalidateIntrinsicContentSize()
    }
}

Images:

First View Expand View ContentSize

Trapani answered 22/2, 2021 at 10:15 Comment(2)
I cant see any nested TableView here. Can you please elaborate how there is nested tableView. Can you please share storyboard Views hierarchy image.Chyle
@Chyle I have main viewController which contains Parent tableview and then I have created ReviewTableViewCell which contains nested child tableView. I have attached my github link for the code.Trapani

© 2022 - 2024 — McMap. All rights reserved.