我的自定义标题部分的.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.
我试图找到不需要的约束并将其删除,但我定义的布局将不再适用于其他设备。忽略这个警告是否安全?我不确定如何调试这个...请帮忙!
答案 0 :(得分:2)
您应该将BtnAdd.trailing
优先级降低到小于1000.看起来autolayout会添加临时约束
"<NSLayoutConstraint:0x61000009ff40 '_UITemporaryLayoutWidth' Project.BillTableSection:0x7ff359d0fc70.width == 0 (active)>"
收集所有内容,因此删除该绝对优先级将让您的内容无冲突地调整。
另外,为什么TxtName.width
== LblPrice.width
?你不能调整内容拥抱优先级吗?