Self-sizing table view cell not sized correctly for initial view load

Originator:keith
Number:rdar://17799811 Date Originated:24-Jul-2014
Status:Closed Resolved:10-Jan-2015
Product:iOS SDK Product Version:8 beta 5
Classification:Other Bug Reproducible:Always
 
Summary:
Using self-sizing table view cell with auto layout as described in WWDC 14 session 226. When the table view is first loaded the on screen cells are not sized correctly (see screenshot-A.png). Scrolling the table down and back to refresh the cells causes them to be redisplayed with the correct row height (see screenshot-B.png).

The table view is created in a storyboard and the estimatedRowHeight is set in viewDidLoad. In addition rowHeight is set to UITableViewAutomaticDimension. It would appear that the initial cells are sized with the rowHeight that is set in the Storyboard.

Steps to Reproduce:
1) Create a new Xcode project based on the single view app but use a single UITableViewController and custom UITableViewCell subclass
2) Configure the storyboard to contain the table view controller embedded in a root navigation controller.
3) Configure the table view prototype cell to use the custom table view class which should contain a single UILabel with auto layout constraints  on the content view. The UILabel number of lines property should be set to 0 in interface builder.
4) Implement the minimal UITableViewDataSource delegate methods to populate the table view with some variable length text in the label of each cell.
5) In viewDidLoad set a value for the estimatedRowHeight property of the table view. Also ensure that rowHeight is set to UITableViewAutomaticDimension.
6) Build and run

Expected Results:
The text label in each cell should contain the full amount of text without clipping. The text label should extend over multiple lines if required and the table view cell sized to fit. (screenshot-B.png)

Actual Results:
On initial load the cells displayed on the screen are clipped and missing  text due to the cell not being sized correctly. (screenshot-A.png)

Scrolling down to move those initial cells offscreen and then scrolling back up to cause the cells to be displayed again will show them correctly sized. (screenshot-B.png)

Version:
iOS 8 Beta 4

Notes:
Example Xcode project to reproduce is attached

Configuration:
iPhone simulator

Attachments:
'SelfSize.zip', 'screenshot-A.png' and 'screenshot-B.png' were successfully uploaded.

Workaround: Add the following to viewDidAppear: in the table view controller to refresh the table view on initial load:
    [self.tableView reloadData];

Comments

I just got bit by the exact same issue. In my case the occasional cell ~1/30 will be the wrong height during scrolling. I am passing the same content to each cell and i believe my constraints are unambiguous vertically. UILabel appears to have random variation in intrinsicContentSize which is unrelated to content.

Definitely an annoying issue

I've found getting these labels to size correctly to be a huge pain!

By tim.walters at Feb. 15, 2015, 6:44 p.m. (reply...)

Resolved

It turns out the problem in my case was that the UILabel had an explicit value set for for the preferred content length. Removing that value so that the preferred width was automatic resolved the problem

I'm experiencing the same thing, I have to do a reloadData on every rotation and transition in order to keep things looking ok. Duplicated.

This bug should really be fixed

This really should be fixed, developers (and me too) continue to be confused and blocked by the problem (see for example http://stackoverflow.com/questions/26840137/single-line-text-takes-two-lines-in-uilabel/26840677)

By valerio.ferrucci at Nov. 10, 2014, 9:47 a.m. (reply...)

UITableView dynamic cell height breaks on transition or rotation

The dynamic cell feature is pretty much useless. I spent 3 days hacking around to make it work, and yet it is not working. Checkout my simple test: https://github.com/ArtworkAD/DynamicCellTest

And related question on stackoverflow: http://stackoverflow.com/questions/26774126/uitableview-dynamic-cell-height-breaks-on-transition-or-rotation

I also noticed, that when you have a UISearchBar above a UITableView inside UITableViewController and you click on the search bar, the table cell height will break. Some cells become bigger.

By ArtjomZabelin at Nov. 6, 2014, 12:40 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!