【问题标题】:Why am I seeing Unable to simultaneously satisfy constraints when using self sizing UITableView cells in iOS 8?为什么在 iOS 8 中使用自行调整大小的 UITableView 单元格时无法同时满足约束?
【发布时间】:2015-10-23 08:42:09
【问题描述】:

自 iOS 8 发布以来,我经常使用自动调整大小的单元格,但最近我遇到了这样的错误:

2015-07-31 08:25:10.610 Evensity[78297:3090623] 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:0x7fbae3485d50 V:[UITextField:0x7fbae3486ab0(55)]>",
    "<NSLayoutConstraint:0x7fbae3424790 V:|-(2)-[UITextField:0x7fbae3486ab0]   (Names: '|':UITableViewCellContentView:0x7fbae3486990 )>",
    "<NSLayoutConstraint:0x7fbae3487480 V:[UITextField:0x7fbae3486ab0]-(2)-|   (Names: '|':UITableViewCellContentView:0x7fbae3486990 )>",
    "<NSLayoutConstraint:0x7fbae0c525a0 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fbae3486990(59)]>"
)

这是一个非常简单的单元格,它只包含一个 UITextField,没有其他内容。

从图中很难看出,但文本字段的高度限制为 55,垂直间距限制(顶部和底部)各为 2。由于自定尺寸,iOS 增加了 UIView-Encapsulated-Layout-Height 垂直尺寸约束 59 (55 + 2 + 2)。这对我来说似乎没有冲突,但我仍然在日志中看到此警告。

另外仅供参考,在进入屏幕后会立即出现损坏的约束消息;它不依赖于滚动来导致单元格重用。

我在这里遗漏了什么可以解释这一点,我该如何纠正?从用户的角度来看,一切似乎都按预期工作。但是,我坚信如果自动布局正在向控制台写入警告,我应该纠正它们,因为它们总有一天会成为问题。

【问题讨论】:

  • 你有没有想过如何摆脱警告?

标签: uitableview ios8 autolayout interface-builder


【解决方案1】:

也许每个都指示自动布局运行时做一些与另一个相矛盾的事情。

也许可以试试:

tableView.translatesAutoresizingMaskIntoConstraints = NO;

【讨论】:

  • 这里不涉及任何自动调整掩码约束;我的问题列出了所涉及的四个约束。其中三个是xib中的约束,第四个是封装好的布局高度约束。 xib 中的三个似乎加起来与封装的布局高度相同,这是有道理的,因为我正在使用自动调整单元格,这些单元格的大小是根据我的自动布局约束来调整的。
猜你喜欢
  • 2014-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-31
  • 1970-01-01
相关资源
最近更新 更多