虽然不是必然的,但看到这些警告是很烦人的:
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:0x19288a20 V:|-(6)-[UILabel:0x19288640] (Names: '|':_UITableViewHeaderFooterContentView:0x192885b0 )>",
"<NSLayoutConstraint:0x19288a70 V:[UILabel:0x19288640]-(6)-| (Names: '|':_UITableViewHeaderFooterContentView:0x192885b0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x19289cd0 h=--& v=--& V:[_UITableViewHeaderFooterContentView:0x192885b0(0)]>" )
Will attempt to recover by breaking constraint <NSLayoutConstraint:0x19288a70 V:[UILabel:0x19288640]-(6)-| (Names: '|':_UITableViewHeaderFooterContentView:0x192885b0 )>
我的约束没有错。UITableViewHeaderFooterView
当视图最初大小为零时,当 UIKit 尝试使用这些约束进行布局时,就会出现此问题。当然,不可能用任何积极的指标来满足任何约束。
一个明显的解决方法是为每个积极指标设置一个低于UILayoutPriorityRequired
优先级或使用NSLayoutRelationLessThanOrEqual
而不是。NSLayoutRelationEqual
但是随后我需要将这些拐杖添加到我对所有视图的所有约束中。更不用说我真正想要的是硬而快而不是可选的约束。
另一种解决方法是为UITableViewHeaderFooterView
. 但是考虑到它的指定 init 方法-initWithReuseIdentifier:
不是-initWithFrame:
,并且它是为 指定框架的责任UITableView
,它也不是一个好的解决方法。UITableViewDelegate
UITableViewHeaderFooterView
那么还有更好的吗?