我在启用AutoLayout
的情况下进行了以下布局:
UIView
UITableView
我有以下约束(这里只重要,其余部分是无效的):
|-(17)-[UITableView:0x15bfc200] priority 1000 (Top space to container)
[UITableView:0x15bfc200]-(17)-| priority 1000 (Bottom space to container)
[UITableView:0x15bfc200](=20) priority 750 (TableView height)
当我尝试将高度设置为零(例如,它没有内容)时,应用停止,但有异常:
Probably at least one of the constraints in the following list is one you don't want...blah blah blah...
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1559bf40 V:[UITableView:0x15bfc200]-(17)-| (Names: '|':UITableViewCellContentView:0x1559b330 )>
目前,我使用以下代码设置身高:
heightConstraint.constant = 0;
将tableView高度设置为零的正确方法是什么?我应该降低某些约束的优先级吗?
答案 0 :(得分:2)
我认为问题在于外部UIView是一个特定的大小。它的高度是54点,所以当你最初设置你的约束时它们起作用。但是当你将高度改为0时,数学不起作用:17 + 0 + 17!= 54。
我不是100%确定你对这个小桌面视图的目标是什么,但我认为你应该能够只用一个顶部约束和一个高度约束来定位它(不需要底部约束)。这将消除您的约束加起来超级视图高度的要求。