Strange UIView-Encapsulated-Layout-Height Error
I'm making test application, so in my tableviewCell in storyboard I have imageView & webView (webview to show html-text).
I set constraints like top/left/right/height=200 for imageView, spacing=5 between them & left/right/bot for webView, so I want to calculate my webView height programmatically and then change cell's height to stretch my webView. But I got this :
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)]>"
)
Any suggestions?
I usually remove this warning by lowering the priority of the constraint that AutoLayout
is trying to break. So if it says:
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fd7c2ecb520 V:[UIView:0x7fd7c2ecd0e0(300)]>
Go ahead and lower that one's priority to 999
.
That should work.
Cheers.
if you use tableView.rowHeight = UITableViewAutomaticDimension
, you should always set estimatedRowHeight
. For example:
tableView.estimatedRowHeight = 44
or you should implement:
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
otherwise you will always get the warning UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView
and the content will be collapsed in a wrong way