I'm using UIView+Autolayout, to make code-based Auto Layout constraint creation easier, but I'm having trouble adding a constraint to a UITableViewCell sub class.
I have a subview ("viewUser") in the cell to group contact information about who posted the other content being shown in the cell. "viewUser" is a fixed height and is always at the bottom of the cell:
To achieve this in the init method I create "viewUser" and add it to the cell's contentView:
self.viewUser = [UIView newAutoLayoutView];
[self.contentView addSubview:self.viewUser];
and in the updateConstraints method I add the following constraints:
[self.viewUser autoSetDimension:ALDimensionHeight toSize:kContentHeight];
[self.viewUser autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:0.0f];
[self.viewUser autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0.0f];
[self.viewUser autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0.0f];
[self.viewUser autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:0.0f];
When I then create the cells, I get the following warning in the console:
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) (
<NSAutoresizingMaskLayoutConstraint:0xb2a6b40 h=--& v=--& V:[UITableViewCellContentView:0xb289e20(44)]>",
"<NSLayoutConstraint:0xb2a3360 V:[UIView:0xb2a5fd0(53)]>",
"<NSLayoutConstraint:0xb2a3420 V:|-(0)-[UIView:0xb2a5fd0] (Names: '|':UITableViewCellContentView:0xb289e20 )>",
"<NSLayoutConstraint:0xb2a3840 UIView:0xb2a5fd0.bottom == UITableViewCellContentView:0xb289e20.bottom>" )
Will attempt to recover by breaking constraint <NSLayoutConstraint:0xb2a3360 V:[UIView:0xb2a5fd0(53)]>
Which to me makes sense because I'm saying that "viewUser" should have a fixed height and then I pin it to the contentView's edges however if I remove:
[self.viewUser autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:0.0f];
When I work out the cell's dynamic height in my tableview controller, its height comes back as 0.
I can't work out what I'm doing wrong and how I remove this warning and get the cell's height, any insights would be great.