1

I have around 30 view controllers that all have a common base class that implements "heighForRowAtIndexPath". Now we have recently removed iOS 7 support which exposes us to the nifty auto-height calculation with AutoLayout. I was just presented with a rather complicated cell that would be great with this automatic height.

The documentation states this:

You may set the row height for cells if the delegate doesn’t implement the tableView:heightForRowAtIndexPath: method. The default value of rowHeight is UITableViewAutomaticDimension.

So it seems that since my baseclass implements the heightFor.. the automatic doesn't take effect.

Is there any way around this? I would somehow need to "de implement" that specific method.

jontelang
  • 589
  • 4
  • 17

1 Answers1

4

You can return UITableViewAutomaticDimension from heightForRowAtIndexPath in your sub class(s):

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewAutomaticDimension;
}
Ahmad F
  • 30,560
  • 17
  • 97
  • 143
Daniel Broad
  • 2,512
  • 18
  • 14
  • Perfect! Thanks a lot. I couldn't seem to find it anywhere written down. – jontelang Oct 19 '16 at 15:58
  • @JonathanWinger-Lang : It is there in Apple documentation for AutoLayout Guide: https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithSelf-SizingTableViewCells.html – Mrunal Oct 20 '16 at 06:07
  • @Mrunal is it? All I can read here is that we must set the table views (not the cells) rowSize to automaticDimension. Nothing about returning it from the delegate method. The rowSize might be connected to the method, but it isn't obvious. It even says that "normally we use the delegate method" which implies that we should NOT use it now, and instead set the rowSize to the table view. Anyway, it seems non obvious to me. – jontelang Oct 20 '16 at 10:03