Custom row height in static UITableView

Correct me if I am wrong, but the only working way to set custom row heights appears to be implementing this method in the table view controller:


override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat{
     return 123.4 // custom height
}

Now here's a chicken-and-egg problem:


I want to set custom row heights in the storyboard designer / interface builder. I can successfully retrieve these height values from the static cells in the viewDidLoad method if I wire them to some IBOutlet. But I cannot access the indexPath for the cells at this point, making it impossible to set up a table with indexPaths and associated heights.


On the other hand, inside "heightForRowAt indexPath" I have (at least initially, for the the very first drawing of the table) no access to the cells (they do not exist in the table, yet), i.e. I cannot read their custom height - all that I have are the indexPaths. I could read them from a pre-built table, but see above: there is no way to build such a table.


Is there really no other way than to hard code index paths and associated heights in "heightForRowAt indexPath"? If so, then what is the point of graphically designing the height if it is completely unusable? Or what am I doing wrong?

Replies

What makes you think that the height values in a static table are ignored?

Note that you probably have to be using storyboards and auto layou (a.k.a the modern tools) for the appropriate design data to be generated.

I am using storyboard and auto layout. Maybe I am missing the right contraints - but which ones?

Remember that child views tend to inherit/obey controls/constraints set on their parents...