Automatic row heights

Hi,


Is there a way I can determine the height of my table rows when automatic row heights are enabled?


I would really like to do this before the table is even visible, not after the rows have been shown.


The problem I need to solve is that I want to size the tableview to fit all the rows without scrolling, but I can't just compute this by multiplying the number of rows by a fixed row height.


Thanks,

Frank

Replies

You should do the computation in viewWillAppear.


This being said, it depends on what you will show in a cell to determine the height.

In general, you don't want to do this before the table is visible, because it's too slow for anything but the smallest of tables.


A more performant approach is to use an estimate for each row, and keep track of which rows are using estimates. When you actually display rows, you can replace the estimate with the correct value.


If you were trying to keep the table at a size that doesn't scroll — assuming you can't use the simpler approach of making the table the same size as the enclosing scroll view, and having white space at the bottom — then you can resize multiple times as row heights are determined. It's a bit more housekeeping than pre-calculating all the heights, but it shouldn't be very hard, and it will scale better to larger tables.