Search code examples
iosswiftuitableviewautolayoutconstraints

UITableView auto resizing row constraint breaking mysteriously on iPhone 6Plus


I have a custom UITableViewCell which has a thumbnail and bunch of text. The row height is configured to be calculated automatically using

tableView.estimatedRowHeight = 129;
tableView.rowHeight = UITableViewAutomaticDimension

The row height should be calculated as exactly 138 points. Everything looks great on the iPhone 5. However, on iPhone 6 Plus, the auto row height fails INTERMITTENTLY for random rows with the following log.

(
    "<NSLayoutConstraint:0x17009ddd0 V:|-(20)-[scoop.ThumbnailImage:0x124d2a5a0]   (Names: '|':UITableViewCellContentView:0x124e23200 )>",
    "<NSLayoutConstraint:0x17009de70 UITableViewCellContentView:0x124e23200.bottomMargin == scoop.ThumbnailImage:0x124d2a5a0.bottom + 20>",
    "<NSLayoutConstraint:0x17009e780 V:[scoop.ThumbnailImage:0x124d2a5a0(90)]>",
    "<NSLayoutConstraint:0x17009ef00 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x124e23200(138.333)]>"
)

The last line of the log seems to say that for some reason the row height was calculated as 138.333 instead of 138. I have been banging my head for a while now but I am unable to figure out why this is happening. Can some one please help?

Update: This is how my table view cell looks like.

cell

UPDATE I couldn't get the code out of the main repo since its a part of a bigger project. But I have managed to reproduce the issue with a very simple sane project. Please find it here on github.


Solution

  • This warning is telling you there's a conflict in your constraints. Reduce the priority of the height constraint to 999 and it will go away. Tested it in your Github project and worked perfectly.

    enter image description here