【问题标题】:Breaking constraints in tableHeaderView打破 tableHeaderView 中的约束
【发布时间】:2015-07-24 07:57:23
【问题描述】:

我将 UILabel 放入 UIView xib。我的 tableView 在 tableHeaderView 中包含该视图。 标签有下一个约束:

在运行时,我在控制台中收到下一个警告:

Unable to simultaneously satisfy constraints.
    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) 
(
    "<NSLayoutConstraint:0x7feaf3969800 H:|-(77)-[UILabel:0x7feaf3968e00'ThreeWithLngNameVeryLong ...']   (Names: '|':HeaderView:0x7feaf3968040 )>",
    "<NSLayoutConstraint:0x7feaf39698a0 H:[UILabel:0x7feaf3968e00'ThreeWithLngNameVeryLong ...']-(16)-|   (Names: '|':HeaderView:0x7feaf3968040 )>",
    "<NSLayoutConstraint:0x7feaf397b4d0 'UIView-Encapsulated-Layout-Width' H:[HeaderView:0x7feaf3968040(0)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7feaf39698a0 H:[UILabel:0x7feaf3968e00'ThreeWithLngNameVeryLong ...']-(16)-|   (Names: '|':HeaderView:0x7feaf3968040 )>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

也许有人知道出了什么问题?

【问题讨论】:

    标签: ios8 autolayout constraints


    【解决方案1】:

    正如我在这里看到的,您在超级视图上设置了尾随和前导基础。 但是你也设置了宽度,我不知道这里的 HeaderView 是什么。 但是Header的宽度可能和标签的约束有关,所以它们是冲突的。

    尝试删除标题宽度限制以检查是否已解决

    【讨论】:

    • 是的,它们有冲突。但问题是它们为什么会发生冲突?因为在 iOS 8 中我们不需要为标签设置宽度。我们有preferredWidth 'Automatic',它在大多数情况下都可以正常工作。(在iOS 7 中,我们需要为此属性设置宽度值)。但是,由于某种原因,当我们将 UIView 放入 tableHeaderView 时,它不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-15
    • 1970-01-01
    • 1970-01-01
    • 2021-08-20
    • 1970-01-01
    相关资源
    最近更新 更多