So, I'm trying to use the inline styles of UITableViewCell - specifically UITableViewCellStyleSubtitle - with a (one) line textLabel but a multi-line detailTextLabel . But the (automatically) calculated cell height is constantly too short and seems to ignore that there are more than 1 row of parts.
I tried using numberOfLines = 0, approxRowHeight, UITableViewAutomaticDimension, preferredMaxWidthLayout, etc., but in all permutations the behavior is valid for all UITableViewCell styles - it looks like the calculation of the cell height of the UITableViewAutomaticDimension correctly takes into account the multi-line textLabel (yay!), But incorrectly that detailTextlabel is not more than one line (no!). Therefore, cells with a multiline TextLabel part are too short, and therefore the contents of the cell spills over the top and bottom of the cell.

I posted a quick testing application showing this behavior on GitHub here . Adding additional lines of text in order - all cell styles increase accordingly in height to accommodate - but adding additional lines of detail does nothing to change the height of the cell and quickly causes the contents to spill; the text + part themselves are laid out correctly and are correctly centered together in the middle of the cell (so in this sense layoutSubviews works correctly), but the overall height of the cell itself does not change.
It looks like there are no actual upper and lower limits between cell.contentView and labels, and instead the cell height is calculated directly from the height of the (possibly multi-line) textLabel and (only one-line) detailTextLabel, and then everything is centered in the middle of the cell ... Again, a multi-line textLabel is fine, and I don't do anything else between textLabel and detailTextLabel, but only the first (correctly) sets the cell height.
So my question is, is it possible to use UITableViewCell's built-in styles to reliably display multi-line detailTextLabels , or is it just not possible and you need to create your own subclass? [or, almost equivalently, without having to override layoutSubviews in a subclass and manually reset all restrictions).
[May 4, 2016]. Conclusion: with multi-line detail, iOS9TextLabels do not work as expected with the UITableViewAutomaticDimension; the cell will be too short, and the text / part will spill from above and below. Either you must manually calculate the correct cell height yourself, or create and place your own equivalent custom subclass of UITableViewCell or (see My answer below) a subclass of UITableViewCell and fix systemLayoutSizeFittingSize:withHorizontalFittingPriority:verticalFittingPriority: to return the correct height [recommended]
ios uitableview autolayout
tiritea
source share