0

So far I've had some success in calculating dynamic table cell layouts with auto layout. And so far, I have maintained different storyboards for iPhone and iPad. I would now like to consolidate them into a single storyboard per app. I'm currently stuck at a point where my height calculations do no longer function.

The trouble is apparently that the table view cell as dequeued from the storyboard is still at its fixed storyboard size (relative to a specific device, i.e. iPhone in my case) when the calculation is first required. It will be resized to fit the actual device (iPad in my case) when the table is displayed. But tableView:heightForRowAtIndexPath: is called before that and therefore does its calculation based on the wrong table cell width.

Is there a good way to solve this problem? It seems as if this accepted answer also isn't immune because its instructions also only mention the cell in isolation from its table view.

First, instantiate an offscreen instance of a table view cell, one instance for each reuse identifier, that is used strictly for height calculations.

Community
  • 1
  • 1
Drux
  • 11,992
  • 13
  • 66
  • 116
  • @smileyborg Could you (as the main author of the cited answer) please have a look at this? Thx. – Drux Jul 03 '14 at 14:23
  • Instead of relying on the table view's `bounds.size` to set the cell width, you could use the view controller's `view.bounds.size` instead (assuming your table view takes the full width, and that the view has already been correctly sized). Or, force the table view to take on the correct width in `viewDidLoad` (which will be before `tableView:heightForRowAtIndexPath:` gets called). – smileyborg Aug 22 '14 at 19:18

0 Answers0