【发布时间】:2014-06-25 16:11:41
【问题描述】:
我正在使用UIView+Autolayout 来简化基于代码的自动布局约束创建,但我在向 UITableViewCell 子类添加约束时遇到了麻烦。
我在单元格中有一个子视图(“viewUser”),用于对有关发布单元格中显示的其他内容的联系人信息进行分组。 "viewUser" 是固定高度,始终位于单元格底部:
为了在 init 方法中实现这一点,我创建了“viewUser”并将其添加到单元格的 contentView:
self.viewUser = [UIView newAutoLayoutView];
[self.contentView addSubview:self.viewUser];
并在 updateConstraints 方法中添加以下约束:
[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];
当我创建单元格时,我在控制台中收到以下警告:
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)]>
这对我来说是有道理的,因为我说“viewUser”应该有一个固定的高度,然后我将它固定到 contentView 的边缘但是如果我删除:
[self.viewUser autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:0.0f];
当我在表格视图控制器中计算单元格的动态高度时,它的高度返回为 0。
我无法弄清楚我做错了什么以及如何删除此警告并获取单元格的高度,任何见解都会很棒。
【问题讨论】:
标签: ios uitableview nslayoutconstraint autolayout