繁体   English   中英

无法同时满足约束自定义标题节

[英]Unable to simultaneously satisfy constraints Custom Header Section

我在表格视图的自定义标头部分有一个.nib:

在此处输入图片说明

override func viewDidLoad() {
        super.viewDidLoad()

    let nib = UINib(nibName: "BillTableSection", bundle: nil)
    billTableView.register(nib, forHeaderFooterViewReuseIdentifier: "BillTableSection")

}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {

    return 44.0
}

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    let cell = billTableView.dequeueReusableHeaderFooterView(withIdentifier: "BillTableSection")

    return cell
}

自定义标头部分有效,但是每当我插入新的部分时,控制台上都会显示一条警告:

2017-10-02 14:56:32.791529+0800 Project[1017:14993] [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:0x61000009f8b0 UIButton:0x7ff359d0d4a0.width == 22   (active)>",
    "<NSLayoutConstraint:0x61000009f900 UITextField:0x7ff359d19660.width == UILabel:0x7ff359d17650'$0.00'.width   (active)>",
    "<NSLayoutConstraint:0x61000009fa90 UITextField:0x7ff359d19660.leading == UIView:0x7ff359d010a0.leadingMargin   (active)>",
    "<NSLayoutConstraint:0x61000009ed20 H:[UITextField:0x7ff359d19660]-(30)-[UILabel:0x7ff359d17650'$0.00']   (active)>",
    "<NSLayoutConstraint:0x61000009f2c0 UIButton:0x7ff359d0d4a0.trailing == UIView:0x7ff359d010a0.trailingMargin   (active)>",
    "<NSLayoutConstraint:0x61000009ee60 H:[UILabel:0x7ff359d17650'$0.00']-(7)-[UIButton:0x7ff359d0d4a0]   (active)>",
    "<NSLayoutConstraint:0x61000009f5e0 H:[UIView:0x7ff359d010a0]-(0)-|   (active, names: '|':Project.BillTableSection:0x7ff359d0fc70 )>",
    "<NSLayoutConstraint:0x61000009f9a0 H:|-(0)-[UIView:0x7ff359d010a0]   (active, names: '|':Project.BillTableSection:0x7ff359d0fc70 )>",
    "<NSLayoutConstraint:0x61000009ff40 '_UITemporaryLayoutWidth' Project.BillTableSection:0x7ff359d0fc70.width == 0   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x61000009f8b0 UIButton:0x7ff359d0d4a0.width == 22   (active)>

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.

我试图找到不需要的约束并将其删除,但是我定义的布局不再适用于其他设备。 忽略此警告是否安全? 我不确定该如何调试...请帮助!

您应该将BtnAdd.trailing优先级降低到小于1000。看来autolayout会添加一个临时约束

"<NSLayoutConstraint:0x61000009ff40 '_UITemporaryLayoutWidth' Project.BillTableSection:0x7ff359d0fc70.width == 0 (active)>"

压缩所有内容,因此删除该绝对优先级将使您的内容进行调整而不会发生冲突。


此外,为什么TxtName.width == LblPrice.width 您不能调整内容优先级吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM