UITableView automatic row heights in Xcode 9 not behaving as expected

I'm in Xcode 9. I have a UITableView.


In the Storyboard, the "Row Height" and "Estimate" values are blank, and the "Automatic" checkbox is set. This should mean that autolayout will be performed on each UITableViewCell, right?


In each tableview cell, I have a view. I've set constraints on this view to bind it to the top & bottom of the "Content View" of the cell. But now I want to add in another constraint to the view, it's height. And I want to set it to 100 pts. Nothing happens, and I get grief from Xcode, saying it needs constraints for "Y position or height". Ugh.


What I wanted to happen here is that Interface Builder would automatically resize my UITableViewCell in the storyboard to 100 pts, because I'm using autolayout and estimated cell sizes. Am I doing this totally wrong? Or does Interface Builder have a bug?

Replies

Trying to understand your case.


Could be that the initial constraints you have already force the height of the view to a value.


So try to change the vertical priorities of the cell from 750 to 800 or 700 (sorry, I never remember which way to change) and from 250 to 200 or 300.


Some explanation here:

h ttps://stackoverflow.com/questions/15850417/cocoa-autolayout-content-hugging-vs-content-compression-resistance-priority

No, I understand the priorities and hugging, etc.


What I'm trying to do is set up my table-view, so that it calculates the height of a cell using autolayout -- but I want to visually see that it works in the storyboard itself.


In Xcode 9, the row-height and estimated row height are automatic. I was assuming that if I added some constraints in the storyboard, that the cell (in the storyboard, not during the app running) would update. But it doesn't seem to.

I tried re-creating your view hierarchy, and I'm running into the same issue.


Not only does Xcode not resize the cells' frames according to what's inside their content views, but it also complaints about missing constraints even though they're all set.

Worse : it actually stops complaining when you try making it happy by manually editing the frame height to what's expected.


In my test, I just added a UIView inside the Content View of a cell, pinned it to the edges and defined a height constraint of 100 pts.

I manually set the row height of the cell to 100 pts.

Xcode keeps telling me that it needs constraints for Y position or height, until I manually define the view frame height to 100 pts. "Update frames" has no effect.


https://imgur.com/a/BfyL6 (unhappy Xcode)

https://imgur.com/a/LbrYU (no constraints added, stops complaining once view height has manually been edited)


This feels like a very annoying bug.

As far as I remember, if I create a xib for a custom cell, then it adapts to the height setting. So it should react if you change constraints and ask for Resolve AutoLayout -> Adapt frames

I've come up against this annyoing bug today - auto sizing table view cells also seem to have issues with stack views containing multi line labels. It's quite painful.

How did you solve it?