【发布时间】:2015-04-09 05:23:04
【问题描述】:
我正在制作测试应用程序,所以在情节提要的 tableviewCell 中,我有 imageView 和 webView(用于显示 html-text 的 webview)。
我为 imageView 设置了 top/left/right/height=200 等约束,它们之间的间距 =5 以及 webView 的 left/right/bot,所以我想要以编程方式计算我的 webView 高度,然后更改单元格的高度以拉伸我的 webView。但我明白了:
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 & fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property
translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7fd6f3773f90 V:[UIImageView:0x7fd6f3773e90(200)]>",
"<NSLayoutConstraint:0x7fd6f3774280 UIImageView:0x7fd6f3773e90.top == UITableViewCellContentView:0x7fd6f3462710.topMargin>",
"<NSLayoutConstraint:0x7fd6f3774320 V:[UIImageView:0x7fd6f3773e90]-(5)-[UIWebView:0x7fd6f3462800]>",
"<NSLayoutConstraint:0x7fd6f3774370 UITableViewCellContentView:0x7fd6f3462710.bottomMargin == UIWebView:0x7fd6f3462800.bottom>",
"<NSLayoutConstraint:0x7fd6f375ee40 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fd6f3462710(205)]>"
)
有什么建议吗?
【问题讨论】:
-
我在iOS8上得到了很多次,我仍然不明白这是否可能是iOS8的一种错误,因为在早期版本中没有引发异常。
-
尝试更换到ios 7.0,但它仍然存在
-
可能是因为 webview 是一个滚动视图被折叠到 0 高度并且当显示单元格时自动布局不能满足顶部和底部约束。尝试在 webview 中放置一个固定的高度,看看是否仍然显示警告
-
我只想将“UIView-Encapsulated-Layout-Height”设置为单元格内容视图的高度(因为我自己在 IB 故事板中使用约束制作内容视图)。我认为设置 tableView.rowHeight = UITableViewAutomaticDimension 并将 tableView.estimatedRowHeight 设置为某个值会起作用(就像在 Ray Wenderlich 教程中所做的那样),但我无法理解!
标签: ios objective-c uitableview webview constraints