I know this is a known issue and has been discussed a lot. However, I've been over a lot of these questions and none of these solutions solve my problem. Also, I work completely in code so no storyboard.
What I have read so far:
- UIView-Encapsulated-Layout-Width / Height Constrained to Zero
- UIView-Encapsulated-Layout with UICollectionView in UIViewController embed in view
- UIView-Encapsulated-Layout-Height and Container View
- What is a 'UIView-Encapsulated-Layout-Width' constraint?
- Strange UIView-Encapsulated-Layout-Height Error
- Auto-layout: What creates constraints named UIView-Encapsulated-Layout-Width & Height?
My case is the following. I am using a UITableView
with sections. Every section has a headerView and footerView. Above this, the entire table also has a headerView and a footerView. So there is one general header and footer, and a header and footer for each section. The header for the entire UITableView
shows a title, the footer shows a "Add Section" and "Post" button. The header for a section shows the title of the section, and the footer for a section shows a "Add Row" button.
I do NOT set estimated heights. I used to, but I removed them as I didn't need estimates, I knew the value it would be (it's not dynamic) - however, removing them or adding them doesn't seem to influence my problem. So there is no estimatedHeightForFooterInSection
, estimatedHeightForHeaderInSection
or estimatedHeightForRowAt
. I add constraints as they should and everything works fine, upon opening the UIViewController
with the UITableView
, there are no errors. However, the Encapsulated-Height or Encapsulated-Width error shows up when I insert a new section (it doesn't happen when I insert a new row):
"<NSLayoutConstraint:0x7ff8557ce1a0 H:|-(15.9574)-[Project.ShadowView:0x7ff8557c8ba0] (active, names: '|':_TtCC5Project26TableViewController14sectionFooter:0x7ff8557c88e0 )>",
"<NSLayoutConstraint:0x7ff8557ce660 Project.ShadowView:0x7ff8557c8ba0.trailing == _TtCC5Project26TableViewController14sectionFooter:0x7ff8557c88e0.trailing - 15.9574 (active)>",
"<NSLayoutConstraint:0x7ff851ea1510 'UIView-Encapsulated-Layout-Width' _TtCC5Project26TableViewController14sectionFooter:0x7ff8557c88e0.width == 0 (active)>"
It also happens, every now and then, with the height instead of width (.height == 0). ShadowView refers to my footerView (which is a custom view with shadow behind it). The constraints for this view are (normalSpacing is a variable determined based on the screen width):
footerView.topAnchor.constraint(equalTo: topAnchor).isActive = true
footerView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -normalSpacing).isActive = true
footerView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: normalSpacing).isActive = true
footerView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -normalSpacing).isActive = true
Important: my views are not broken, everything works as expected, the error only shows up in my console and makes me want to fix it. So what is this, where does it come from and above all: how do I fix it?