如何告诉UITableView自定型单元的高度即将发生变化?

我有一个UITableView,其内容有点动态。 似乎每次我调整它们的大小时,我都会遇到这个错误:

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) ( "", "", "", "" ) 

这是最后一个 – 标记为UIView-Encapsulated-Layout-Height那个 – 正在破坏事物。 我想摆脱它,或者将它设置为优先级,或者其他东西 – 但我似乎无法告诉UITableView打破它。 我已经在各种视图上尝试了setNeedsUpdateConstraintssetNeedsLayout所有可能组合。 我已经尝试从updateConstraints上的单元格的contentView删除所有约束。 我试过调用beginUpdatesendUpdates – 在这种情况下,永远不会调用updateConstraints ,并且不会重新评估约束。

我在这里不知所措。 如果没有自定义单元格,只需调用begin / endUpdates来触发重新计算单元格的尺寸。 我现在该怎么办?

您在内容视图中使用的WKWebView是破坏约束的最可能原因。 此外,只有在WebView完成加载后才能计算任何webView的高度。 例如,在UIWebView中,只能在delgate方法“didFinishLoadingWebView”方法中适当地获取UIWebView的高度。

此外,’UIView-Encapsulated-Layout-Height’约束据称不满意,因为计算的单元的固有高度可能具有不同的值。 因此,可以降低相关单元约束的优先级,以允许UIView-Encapsulated-Layout-Height具有优先权。