I have a table view with a bunch of cells (custom cell, which only has its content view).
In tableView:cellForRowAtIndexPath:
I'm adding a predefined UIView (which has several subviews) to the content view of the custom cell. I set up all constraints for the UIView and its subviews before.
Last but not least, I set the vertical and horizontal constraints for the content view of my custom cell (superview) and the UIView, which was added before (subview).
The constraint strings look like this:
H:|[view]|
V:|[view]|
Unfortunately, I still get the default height for all table view cells. I'm wondering If there's a way to let auto layout do the calculation of the height automatically according to content size.
tableView:heightForRowAtIndexPath
and return a height or the default height of the cell will be used. – Robotic CatUITableViewCells
you could create a method in the subclass that returns the height for that cell and then call that method intableView:heightForRowAtIndexPath
. Obviously, try to make the calculation fast and efficient (possibly pre-calculate the result on any change and cache the result if the calculation is very complex). – Robotic Cat