バックグラウンド
これはこの投稿を参照しています (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()
これは奇妙なことですが、どこにも文書化されておらず、物事の壮大な計画では意味がありません。
参照用のUITableViewCell コード全体を次に示します。