Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView cell height setting life-cycle
    text
    copied!<p>Trying to understand when the cell height is set. I have a UITableView that is created in layout, not code.</p> <p>Then:</p> <pre><code>#define TABLE_VIEW_ROW_HEIGHT 100.0 </code></pre> <p>Followed by:</p> <pre><code>-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"Setting row height"); return TABLE_VIEW_ROW_HEIGHT; } </code></pre> <p>and</p> <pre><code>-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"Row height: %f", tableView.rowHeight); // ... other happy stuff that does not change row height but could sure use the real row height </code></pre> <p>The last NSLog reports 44 rather than 100. Which means that the code within that method that needs to get the row height is not using the real height.</p> <p>I've verified that </p> <pre><code>-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath </code></pre> <p>runs before</p> <pre><code>-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath </code></pre> <p>And, as a result, the rows are of the desired size, not the default size of 44.</p> <p>Do I need to explicitly set the height somewhere else?</p> <p>EDIT AFTER DOING SOME RESEARCH:</p> <pre><code>-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath </code></pre> <p>...is more appropriately used to set the height of rows when not all rows are of the same height. I was wrongly using this to set all rows to the same height.</p> <p>The right way to do it is to call</p> <pre><code>the_tableview.rowHeight = TABLE_VIEW_ROW_HEIGHT; </code></pre> <p>...from somewhere like viewDidLoad. I actually did that (code omitted) but it didn't work. Tonight I realized that this is yet another instance of being had by the graphical layout tool...I forgot to connect the IBOutlet for the UITableView...so, my code did nothing and the entire tableview remained at the default height of 44. That's why I was getting 44 out of my NSLog.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload