虽然没有后果,但看到这些警告是非常烦人的:
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 )>
Run Code Online (Sandbox Code Playgroud)
我的约束没有错.UITableViewHeaderFooterView当视图最初为零大小时,UIKit尝试使用这些约束进行布局时会出现此问题.当然,任何积极的指标都不可能满足任何约束.
一个明显的解决方法是设置低于UILayoutPriorityRequired优先级或使用NSLayoutRelationLessThanOrEqual而不是NSLayoutRelationEqual每个正面指标.但是我需要将这些拐杖添加到我对所有观点的所有约束中.更不用说我真正想要的是硬而快,而不是可选约束.
另一种解决方法是为其设置初始帧UITableViewHeaderFooterView.但是考虑到其候init方法是-initWithReuseIdentifier:不是-initWithFrame:和它的责任UITableView,并UITableViewDelegate指定帧UITableViewHeaderFooterView,既不感觉良好的解决方法.
那么更好的吗?
lar*_*cus 10
我认为你的特殊问题源于试图在一个实例上设置"容器"大小限制UITableViewHeaderFooterView.问题类似于想要根据此处询问的自动布局来设置单元格大小.
特别是对于这个问题,视图的大小为零,但约束规定视图在维度上至少为 12pt(违反当前状态).在这种情况下尤其违反这一点,并且由于页眉/页脚视图使用框架/自动调整遮罩而非自动布局来调整大小,因此无法处理,因此例外.
这种情况有两种选择:
layoutSubviews非零bounds.size,或者(如果你还没有)updateConstraints您的UITableViewHeaderFooterView子类.updateConstraints检测到self.bounds.size不存在时才会安装自动布局约束CGSizeZero(这将是正确的解决方案).| 归档时间: |
|
| 查看次数: |
1750 次 |
| 最近记录: |