13
votes

I have UIViewController 1 , that has scroll view. Inside this scrollview there is container view that pinned to top/bottom leading/trailing (without fixed height). Container view has UITableView pinned to top/bottom trailing/leading and height constraint with 0 constant, that will change in updateViewConstraints 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-Height? How can i skip it?Because it breaks "right" constraint(that i update to content size height).Thanks

7
Think it's the height of your tableview cell. How are you setting that?beyowulf
I didn't have any constraints on cell. Cell height determine by heightForRowAtIndexPath: , that returns tableView.rowHeight. How is it possible?ThanksSerd
What shows up when you build and run? Have you tried changing the background color of your views so you can see how they're being drawn?beyowulf
Shown container view with zero height. But i want to make it the size, based on content view, but NSLayoutConstraint:0x7b03e5f0 V:[UITableView:0x7c42a200(54)] was dropped, because this constraint NSLayoutConstraint:0x7b65f900 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7b0b7000(0)]Serd
How can make container view have a height based on content views(content views has right constraints for Width/Height i'm sure)?Serd

7 Answers

26
votes

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!

18
votes

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.

9
votes

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:

enter image description here

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:

enter image description here

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.

2
votes

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.

0
votes

These issues occurs when there is a clash between the constraint.

In your case, you have already given top/bottom leading/trailing constraint to inner table view,which satisfy required constraint for table view, so there is no need of providing one more constraint (fixed height constraint with constant 0) to it.

NSLayoutConstraint:0x7b03e5f0 V:[UITableView:0x7c42a200(54)], NSLayoutConstraint:0x7b0ba120 V:|-(0)-[UITableView:0x7c42a200]

above two line means there is some clash in vertical direction for table view which has constant 0.

Two ways you can resolve this,

1 - Remove height constraint, set bottom constraint to zero initailly. Take an outlet of bottom constraint and set bottom constraint value dynamically.

2 - Remove bottom space constraint, set height constraint to zero. Take an outlet of height constraint and set height of table view dynamically.

Hope this will help you.

0
votes

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)

drawing

-1
votes

Set the container view's height constraint. Create an IBOutlet of said height constraint call it "containerViewHeightConstraint" or something. When you update the table view's height constraint to 54, say something like:

self.containerViewHeightConstraint.constant = 54.0;