Why does heightForRowAtIndexPath: come before cellForRowAtIndexPath:?
cocoa-touch, ios, uitableview
Solution
Best guess: `UITableView` needs to know the total height of all cells so that it can know the percentage of scroll for the scroll bar and other needs.
Problem
Almost every time I write an app for a client I have to implement some kind of 'hack' to get `UITableViewCell`s to dynamically become the right height. Depending on the content of the cells this can vary in difficulty. I usually end up running through code that formats the cell twice, once in `heightForRowAtIndexPath:` and then again in `cellForRowAtIndexPath:`. I then use an array or dictionary to store either the height or the formatted cell object. I've probably written and rewritten this code 20 times over the past 2 years. Why did Apple implement it in this order? It would be much more straightforward to configure the cells and THEN set the height either in `cellForRowAtIndexPath:` or shortly thereafter in `heightForRowAtIndexPath:`. Is there a good reason for the existing order? Is there a better way to handle it?