Ad

Our DNA is written in Swift
Jump

Radar: UITableViewAutomaticDimension

For an event calendar I am showing a table view with dynamically sized cells. There are two labels which can span multiple lines. Unfortunately automatic sizing of the cell height via UITableViewAutomaticDimension does not work consistently in iOS 8 and 9.

Filed as rdar://22193223 and on OpenRadar.

Tableview automatic dimension might truncate labels until first cell reuse

Summary

I have a cell that has a variable height label for the first line. I found that using automatic dimension some of the cells are sized incorrectly causing this label to be truncated. If I reloadData in viewDidAppear, the size becomes correct.

Steps to Reproduce

  1. Look at the two screen shots provided
  2. Notice that in one the bold label shows the …

The screen shot with the earlier time stamp is without the workaround, the one with the later time stamps has the reloadData as discussed.

Cut Off

Not Cut Off

Expected Results

There should always be all lines visible of the text on the bold label

Actual Results

Some cells (even off screen) get an incorrect size. Only if you reload the cells AFTER the view has appeared on screen the size becomes correct.

Notes

I believe that this Stack Overflow question describes the same issue.

When Apple asked me if the problem still occurred on the latest iOS 9 seed, I pulled the essential bits from my app into a sample: AutomaticHeightBug on my Radar Samples GitHub repo. There I use the same table view cell – configured in storyboard – as in the app from which the above screen shots came.

Not only does this show that the problem still exists in iOS 9 (SDK and/or device) but it also demonstrates how even exactly the same text results in different automatic row heights.

Mixed Cut Off Sample

The sample though puzzles me insofar as that there it is always the bottom right label that experiences the truncation. Also, reloading the table view doesn’t magically fix the layout as it does in my app. But at least the core issue is demonstrated by it: Labels with a vertical compression resistance of 1000 should never be truncated like shown.

I am aware of different ways how people are trying to work around this bug: calling layoutIfNeeded, setting the cell frame and reloading the table view. But my point is, those should not be necessary. This issue – which is present even in iOS 8 – should finally be resolved.


Categories: Bug Reports

Leave a Comment