我有一个 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)
(
"<NSLayoutConstraint:0x15dbabf0 WKWebView:0x15da1650.top == UITableViewCellContentView:0x15eaedb0.topMargin>",
"<NSLayoutConstraint:0x15dbac20 UITableViewCellContentView:0x15eaedb0.bottomMargin == WKWebView:0x15da1650.bottom>",
"<NSLayoutConstraint:0x15db1360 V:[WKWebView:0x15da1650(158)]>",
"<NSLayoutConstraint:0x15ed0c00 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x15eaedb0(43.5)]>"
)
就是最后一个 - 标记为
UIView-Encapsulated-Layout-Height
的那个- 那是破坏事物。我想摆脱它,或者将其设置为破坏优先级,或者其他什么 - 但我似乎无法告诉 UITableView 破坏它。我已经尝试了 setNeedsUpdateConstraints
的所有可能组合和 setNeedsLayout
关于各种观点。我已经尝试从单元格的 contentView
中删除所有约束。在 updateConstraints
.我试过调用beginUpdates
和 endUpdates
- 在这种情况下,updateConstraints
永远不会被调用,并且不会重新评估约束。我很茫然,在这里。如果没有自调整单元格,只需调用 begin/endUpdates 即可触发重新计算单元格的尺寸。我现在该怎么做?
最佳答案
您在内容 View 中使用的 WKWebView 是破坏约束的最可能原因。此外,任何 webView 的高度只能在 WebView 完成加载时计算。例如,在 UIWebView 中,只能在 delgate 方法“didFinishLoadingWebView”方法中适本地获取 UIWebView 的高度。
此外,“UIView-Encapsulated-Layout-Height”约束可能不会得到满足,因为计算出的单元格的固有高度可能具有不同的值。因此,可以降低相关单元格约束的优先级以允许 UIView-Encapsulated-Layout-Height 具有优先权。
关于ios - 如何告诉 UITableView 自调整单元格的高度即将改变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28059581/