UIView-Encapsulated-Layout-Height and Container View
Solution 1
Finally i solve this problem.
1. In your tableView setting, set: tableView.estimatedRowHeight = 100
.
2. In the last view of your cell, set: make.bottom.equalTo(contentView).priority(999)
.
3. Run your code, maybe it's ok!
Solution 2
Finally i found a problem. View that is added as subview to container view has translatesAutoresizingMaskIntoConstraints = YES, so NSLayoutConstraint:0x7b65f900 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7b0b7000(0)] was appeared and made me some problems. Add runtime attribute translatesAutoresizingMaskIntoConstraints = NO and it'll fix the issue.
Solution 3
Chiming in with one of the easiest ways to solve this: Just lower the priority of the autolayout rule that is bound to the bottom edge of your container view.
Here's my container:
I'm telling that image view to follow the bottom edge of the container, and that was giving me a conflict. To fix it, I can just lower the priority of that bottom edge rule:
I say "bottom" because in my estimation that's probably the one you'll have a conflict with, but it could be any edge that implicitly sets a width on your container.
Solution 4
Rather than manually setting translatesAutoresizingMaskIntoConstraints
on the contentView
of the cell or manually adjusting the height of this view, you should just set estimatedRowHeight
and rowHeight
for the tableview, as discussed in WWDC 2014 video What's New in Table and Collection Views:
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.estimatedRowHeight = 44;
self.tableView.rowHeight = UITableViewAutomaticDimension;
}
Then the fully qualified constraints you apply to that cell will adjust the row height and eliminate those annoying warnings.
Solution 5
Go on the item's container's xib -> deselect "Autoresize Subviews" under the "drawing" section. It fixed it for me. (The item is the item that's giving you the constraints conflict)
Serd
Updated on June 12, 2022Comments
-
Serd almost 2 years
I have
UIViewController 1
, that hasscroll view
. Inside thisscrollview
there iscontainer view
that pinned totop/bottom leading/trailing
(without fixed height).Container view
hasUITableView
pinned totop/bottom trailing/leading
andheight constraint with 0 constant
, that will change inupdateViewConstraints
to content size height.When View of UIViewController 1 appears, Container View has constraint:
NSLayoutConstraint:0x7b03e5f0 V:[UITableView:0x7c42a200(54)], NSLayoutConstraint:0x7b0ba120 V:|-(0)-[UITableView:0x7c42a200] (Names: '|':UIView:0x7b0b7000 ), NSLayoutConstraint:0x7b0ba1b0 V:[UITableView:0x7c42a200]-(0)-| (Names: '|':UIView:0x7b0b7000 ), NSLayoutConstraint:0x7b65f900 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7b0b7000(0)]
Will attempt to recover by breaking constraint
NSLayoutConstraint:0x7b03e5f0 V:[UITableView:0x7c42a200(54)]
What is
UIView-Encapsulated-Layout-Heigh
t? How can i skip it?Because it breaks "right" constraint(that i update to content size height).Thanks -
Serd over 8 yearsThanks for answer, but containerViewHeightConstraint and TableViewConstraint are in different view controllers. How can i know in view controller 1 ,when tableview constraint changed?Thanks
-
beyowulf over 8 yearsYou can use delegation or NSNotificationCenter
-
Serd over 8 yearsIt's bad approach, i hope(and sure) that there is better solution.Nevertheless Thanks
-
beyowulf over 8 yearsReally the bad approach is using child view controllers. You should avoid that practice. But I tried to tell you, what you're saying makes no sense. You're pinning everything to the edges then setting the height to zero, you must be getting warnings or errors from auto layout. You should investigate those.
-
Serd over 8 yearsI only have working from scroll view, where container is pinned, because scroll view can not determine it's content size. But what i want - is that container view has height base on the content it's represent. Thanks
-
Serd over 8 yearsThe main problem for me is this constraint - NSLayoutConstraint:0x7b65f900 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7b0b7000(0)
-
João Nunes over 8 yearsThis solved my problem! After the container view is added. Use the prepareForSegue method to get to the view,then set to false the translatesAutoresizingMaskIntoConstraints of that view
-
Serd over 8 yearsit also can be set in interface builder in runtime attributes
-
Protongun almost 8 yearsThank you! I was adding a child view controller (not using container views, explicitly in code) and I had forgotten to set the child VC's view's translatesAutoresizingMaskIntoConstraints property to false
-
Kyle Browning about 6 yearsHoly crap I searched for a long time and this actually worked.
-
Thippi almost 6 yearsThanks , its really helped to me, I searched alot for this issue
-
Diego Carrera over 5 yearsThank you, It worked great and the warning disappeared.
-
Robert Haworth over 5 yearsLowering the priority of your final connecting constraint to the cell's contentView is exactly the right answer it seems. This also holds true for UICollectionViewCell's if you see this same issue.
-
Asike about 4 yearsThanks! With SnapKit I made $0.bottom.equalToSuperview().offset(-5).priority(.low)