背景
这是参考这篇文章(TLDR;如果您正确使用自动布局,则应自动计算 UITableViewCell 高度)。
问题
如果我将视图直接添加到contentView
,我会不断收到此错误:
018-11-25 02:17:33.514881+0200 [78571:855018] [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:0x2825f0be0 V:|-(76)-[.TTRLabel:0x10e7c7e40'DRIVER'] (active, names: '|':UITableViewCellContentView:0x10e7cb700 )>",
"<NSLayoutConstraint:0x2825f0b90 V:[.TTRLabel:0x10e7c7e40'DRIVER']-(10)-[.TTRLabel:0x10e7c8420'TIME'] (active)>",
"<NSLayoutConstraint:0x2825f1c70 V:[.TTRLabel:0x10e7c8420'TIME']-(10)-[.TTRLabel:0x10e7c8a00'ADDRESS'] (active)>",
"<NSLayoutConstraint:0x2825f1ea0 .TTRLabel:0x10e7c96a0' new office '.bottom == UITableViewCellContentView:0x10e7cb700.bottom - 26 (active)>",
"<NSLayoutConstraint:0x2825f1f40 .TTRLabel:0x10e7c96a0' new office '.lastBaseline == .TTRLabel:0x10e7c8a00'ADDRESS'.lastBaseline (active)>",
"<NSLayoutConstraint:0x2825f34d0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x10e7cb700.height == 44 (active)>"
)
我的问题是这部分
<NSLayoutConstraint:0x2825f34d0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x10e7cb700.height == 44 (active)>"
它坚持 tableViewCell 高度只是标准的 44 (因此忽略了我所有的自动布局工作!
唯一能解决问题的就是运行这个
self.contentView.autoPinEdgesToSuperviewEdges()
这很奇怪,b/c 它没有记录在任何地方,并且在宏伟的计划中没有意义。
这是整个UITableViewCell 代码供参考。