为什么Xcode控制台会打印约束不明确的警告,但UI调试器却没有?

时间:2018-12-09 05:01:04

标签: ios swift uitableview

我有一个自定义的UITableViewCell,看起来像这样,没什么复杂的:

enter image description here

约束为:

  1. 水平间距为16

  2. 实际上,所有间距都是16:male.top = 16,male.bottom = 16,female.centerY = male.centerY,other.centerY = female.centerY

  3. 按钮的宽度相等:female.width = male.width,other.width = female.width

  4. 按钮的高度等于35,male.height = 35,female.height = male.height,other.height = female.height

此代码为:

for button in [maleButton, femaleButton, otherButton] {
    button.translatesAutoresizingMaskIntoConstraints = false
    contentView.addSubview(button)
}

var constraints: [NSLayoutConstraint] = []

constraints += NSLayoutConstraint.constraints(
    withVisualFormat: "H:|-16-[male]-16-[female]-16-[other]-16-|",
    options: [],
    metrics: nil,
    views: ["male": maleButton, "female": femaleButton, "other": otherButton]
)

constraints += NSLayoutConstraint.constraints(
    withVisualFormat: "V:|-16-[male(35)]-16-|",
    options: [],
    metrics: nil,
    views: ["male": maleButton]
)

constraints.append(
    NSLayoutConstraint.init(
        item: femaleButton,
        attribute: .height,
        relatedBy: .equal,
        toItem: maleButton,
        attribute: .height,
        multiplier: 1,
        constant: 0
    )
)

constraints.append(
    NSLayoutConstraint.init(
        item: femaleButton,
        attribute: .width,
        relatedBy: .equal,
        toItem: maleButton,
        attribute: .width,
        multiplier: 1,
        constant: 0
    )
)

constraints.append(
    NSLayoutConstraint.init(
        item: femaleButton,
        attribute: .centerY,
        relatedBy: .equal,
        toItem: maleButton,
        attribute: .centerY,
        multiplier: 1,
        constant: 0
    )
)

constraints.append(
    NSLayoutConstraint.init(
        item: otherButton,
        attribute: .height,
        relatedBy: .equal,
        toItem: femaleButton,
        attribute: .height,
        multiplier: 1,
        constant: 0
    )
)

constraints.append(
    NSLayoutConstraint.init(
        item: otherButton,
        attribute: .width,
        relatedBy: .equal,
        toItem: femaleButton,
        attribute: .width,
        multiplier: 1,
        constant: 0
    )
)

constraints.append(
    NSLayoutConstraint.init(
        item: otherButton,
        attribute: .centerY,
        relatedBy: .equal,
        toItem: femaleButton,
        attribute: .centerY,
        multiplier: 1,
        constant: 0
    )
)

NSLayoutConstraint.activate(constraints)

控制台中的警告消息是:

enter image description here

但是,当我尝试使用UI Debugger时,没有出现运行时约束不确定性警告,为什么?我应该担心控制台中的此警告消息吗?

0 个答案:

没有答案