The problem is that I have a table whose cells have dynamic height. Those. The cell is custom and in a storyboard its design is built on constraints. When loading a table from the Internet, the content is loaded, which is loaded into the array and then the table is updated and the cells are filled, and their height depends on the content and can vary greatly.

At first I ran into the problem that, due to the different heights, when updating one of the cells, the table scrolled a little. I was helped to solve this problem here.

And it would seem that the problem has been solved. But now I added a header to my table. And his height also changes dynamically. As I understand it, so that there is no shift and the table does not scroll when updating the cells, I need to add the following lines to viewDidLoad:

self.tableView.sectionHeaderHeight = UITableViewAutomaticDimension self.tableView.estimatedSectionHeaderHeight = ? 

But I need to know the height of the header. How to do it? If I do this:

 override func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { self.tableView.estimatedSectionHeaderHeight = view.frame.height } 

then I get the height that I originally set myself in viewDidLoad. And I need the real height of the header, taking into account all the content that is there.

    2 answers 2

    The estimatedSectionHeaderHeight is needed to improve the loading performance of the table view. You can specify an average value, then some geometry calculations will occur during scrolling.

    • Try to write more detailed answers. Explain what is the basis of your statement? - Nicolas Chabanovsky
    • The question is absolutely not about that. And how to find out the height of the header. But in principle, no longer relevant, since I found an alternative to heder. - cheerful_weasel

    If you use autolayout, you can use the systemLayoutSizeFittingSize method, it allows you to calculate the actual height of the view.

    • Try to write more detailed answers. Explain what is the basis of your statement? - Nicolas Chabanovsky
    • And where exactly to call it? - cheerful_weasel