Jonathan Winger-Lang Jonathan Winger-Lang - 1 year ago 93
Objective-C Question

How can I use UITableViewAutomaticDimension when the baseclass implements tableView:heightForRowAtIndexPath:

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.

Answer Source

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

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewAutomaticDimension;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download