Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewAutomaticDimension breaking constraints?

I'm trying to use UITableViewAutomaticDimension, but I'm having trouble getting a cell to be full width and the correct height without causing NSLayoutAutomaticSizeConstraint... issues. If I turn auto size constraints off on the cell, it is not full width.

enter image description here

I have two buttons with horizontal and vertical constraints to the content view. They have a vertical spacing constraint between each other, and each button has a height constraint.

If I turn off AutoResizingMask, I get a not-full width cell. If I leave it on, I get layout constraint violations but things render correctly.

How can I get the behavior I'm looking for?

translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7f856b169650 V:[UIButton:0x7f856b16a510'+(null)'(50)]>",
    "<NSLayoutConstraint:0x7f856b173dd0 UIButton:0x7f856b16a510'+(null)'.top == UITableViewCellContentView:0x7f856b16bfa0.topMargin>",
    "<NSLayoutConstraint:0x7f856b173e70 UITableViewCellContentView:0x7f856b16bfa0.bottomMargin == UITextField:0x7f856b16c4f0.bottom>",
    "<NSLayoutConstraint:0x7f856b174520 V:[UIButton:0x7f856b16a510'+(null)']-(8)-[UITextField:0x7f856b16c4f0]>",
    "<NSLayoutConstraint:0x7f856b182a10 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7f856b16bfa0(66)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f856b169650 V:[UIButton:0x7f856b16a510'+(null)'(50)]>

It actually looks like the width is set by

- (CGSize)intrinsicContentSize {
    return CGSizeMake(320, 66);
}

If I don't set an intrinsic content size, I don't get any width or height.

like image 961
Stefan Kendall Avatar asked Sep 29 '22 08:09

Stefan Kendall


1 Answers

edit: Its definitely the two height constraints. Try removing one, or lowering priority.

like image 136
hidden-username Avatar answered Oct 03 '22 06:10

hidden-username