Unsatisfiable constraints for UITableView header - UIView-Encapsulated-Layout-Width width == 0

I have a UITableView section header with a bunch of labels in it where some of those labels have a fixed width in order to look like table columns (same with is used in corresponding table view cells).



I'm gettting the following auto layout error when the table view data is reloaded:


2017-08-14 13:14:25.765634+0600 ONSITE[61409:29214827] [LayoutConstraints] 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.

(

"<NSLayoutConstraint:0x608000490db0 UILabel:0x7fcfd2d9fda0'STATUS / ID'.width == 100 (active)>",

"<NSLayoutConstraint:0x6080004906d0 UILabel:0x7fcfd2da02c0'TRADE'.width == 100 (active)>",

"<NSLayoutConstraint:0x608000490630 UIImageView:0x7fcfd2da0550.width == 48 (active)>",

"<NSLayoutConstraint:0x608000490950 H:|-(30)-[UILabel:0x7fcfd2d9fda0'STATUS / ID'] (active, names: '|':UIView:0x7fcfd2d9fc00 )>",

"<NSLayoutConstraint:0x6080004909f0 H:[UILabel:0x7fcfd2d9fda0'STATUS / ID']-(5)-[UILabel:0x7fcfd2da0030'DESCRIPTION'] (active)>",

"<NSLayoutConstraint:0x608000490860 H:[UILabel:0x7fcfd2da0030'DESCRIPTION']-(5)-[UILabel:0x7fcfd2da02c0'TRADE'] (active)>",

"<NSLayoutConstraint:0x6080004908b0 H:[UILabel:0x7fcfd2da02c0'TRADE']-(8)-[UIImageView:0x7fcfd2da0550] (active)>",

"<NSLayoutConstraint:0x6080004909a0 H:[UIImageView:0x7fcfd2da0550]-(0)-| (active, names: '|':UIView:0x7fcfd2d9fc00 )>",

"<NSLayoutConstraint:0x608000490270 H:|-(0)-[UIView:0x7fcfd2d9fc00] (active, names: '|':UIView:0x7fcfd2d9fa60 )>",

"<NSLayoutConstraint:0x608000490220 H:[UIView:0x7fcfd2d9fc00]-(0)-| (active, names: '|':UIView:0x7fcfd2d9fa60 )>",

"<NSLayoutConstraint:0x608000490720 H:|-(0)-[UIView:0x7fcfd2d9fa60] (active, names: '|':ReworkListHeaderView:0x7fcfd2cadb00 )>",

"<NSLayoutConstraint:0x608000499500 H:[UIView:0x7fcfd2d9fa60]-(0)-| (active, names: '|':ReworkListHeaderView:0x7fcfd2cadb00 )>",

"<NSLayoutConstraint:0x60800048fe10 'UIView-Encapsulated-Layout-Width' ReworkListHeaderView:0x7fcfd2cadb00.width == 0 (active)>"

)

Will attempt to recover by breaking constraint

<NSLayoutConstraint:0x6080004906d0 UILabel:0x7fcfd2da02c0'TRADE'.width == 100 (active)>


Where does the "UIView-Encapsulated-Layout-Width" constraint come from? How can I avoid this error?


After some googling all I found are suggestions to lower constraint priorities, which would be the priorities of the width constraints of my labels, to something like 999. But is this really a good solution? I feel like there must be a better way.


I don't want to change constraint priorities because some other outisde view is imposing its own constraints out of nowhere. And I will most certainly forget about this when adding another label to this header and creating a new header view for another table. Therefore I'd like to avoid doing this.


Is messing with constraint priority numbers the way things are supposed to be done with auto layout? I don't like magic numbers at all, it's too easy to brek stuff (well at least if you 're working with Interface Builder, perhaps in code it's not as bad).

Did you ever find a work-around for this? I'm having the same issue with self-sizing table view cells.

Hi, I had a similar issue: I got a width constraint with constant 0 for my table header view out of nowhere...

And it's conflicting with my existing horizontal constraints

Then I found this article: https://medium.com/@aunnnn/table-header-view-with-autolayout-13de4cfc4343

I think I sort of work around of this problem by creating a containerView to hold my actual header...

Anyway, hope this helps. 🙂

Unsatisfiable constraints for UITableView header - UIView-Encapsulated-Layout-Width width == 0
 
 
Q