隐藏表格视图单元格时出现沉默约束错误

时间:2019-04-11 18:51:20

标签: ios xcode tableview constraints

我有一个表格视图,每个单元格内都有一个标签:

tableview

我为标签设置了三个约束:

enter image description here

我通过将高度设置为零并将其isHidden属性设置为true来根据某些条件在代码中隐藏一些单元格,当发生这种情况时,我会在控制台中找到它:

[LayoutConstraints] 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. 
(
    "<NSLayoutConstraint:0x282c606e0 UILabel:0x157edf690'0'.top == UITableViewCellContentView:0x157edf250.topMargin + 2.5   (active)>",
    "<NSLayoutConstraint:0x282c60730 UITableViewCellContentView:0x157edf250.bottomMargin == UILabel:0x157edf690'0'.bottom + 2.5   (active)>",
    "<NSLayoutConstraint:0x282c60870 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x2836915e0'UIViewLayoutMarginsGuide']-(8)-|   (active, names: '|':UITableViewCellContentView:0x157edf250 )>",
    "<NSLayoutConstraint:0x282c60e10 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x157edf250.height == 0   (active)>",
    "<NSLayoutConstraint:0x282c607d0 'UIView-topMargin-guide-constraint' V:|-(8)-[UILayoutGuide:0x2836915e0'UIViewLayoutMarginsGuide']   (active, names: '|':UITableViewCellContentView:0x157edf250 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x282c60730 UITableViewCellContentView:0x157edf250.bottomMargin == UILabel:0x157edf690'0'.bottom + 2.5   (active)>

现在我有两个问题:

1-忽略此警告是否安全?

2-我知道这可能有助于降低其中一个约束的优先级。但是应该是哪一个?为什么?

0 个答案:

没有答案