0

I have a UICollectionViewCell with autolayout constraints. It works as aspected but my application prints a lot of warnings about unsatisfied constraints:

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:0x7f9e650c50f0 UILabel:0x7f9e650c10c0'Toz     Kat Elek >30'.top == UIView:0x7f9e650c0fd0.topMargin - 8>",
    "<NSLayoutConstraint:0x7f9e650c51e0 UIView:0x7f9e650c17f0.top == UILabel:0x7f9e650c10c0'Toz     Kat Elek >30'.top + 20>",
    "<NSLayoutConstraint:0x7f9e650c5280 UIView:0x7f9e650c0fd0.bottomMargin == UIView:0x7f9e650c17f0.bottom - 8>",
    "<NSAutoresizingMaskLayoutConstraint:0x7f9e650d8550 h=--& v=--& V:[UIView:0x7f9e650c0fd0(0)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f9e650c5280 UIView:0x7f9e650c0fd0.bottomMargin == UIView:0x7f9e650c17f0.bottom - 8>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

I have tried lots of different combinations to find out the source of the problem. While inspecting my view hierarchy with Debug View Hierarchy I found out that there is an UIView that I didn't add and this UIView causes the warning messages. Hidden UIView

So how can get rid of these warning messages?

UPDATE

Here is my view hierarchy:

hierarchy

view

Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112

4 Answers4

1

OK, I have found my answer here: Auto layout constraints issue on iOS7 in UITableViewCell

The problem was about hidden content view of the cell. To get rid of the errors do following before returning the cell in cellForItemAtIndexPath:

cell.contentView.frame = cell.bounds;
cell.contentView.autoresizingMask =
UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleBottomMargin;
Community
  • 1
  • 1
Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112
0

I think the problem is not about that hidden view. UICollectionViewCell has a contentview like UITableViewCell. The constraint conflict seems about UILabel.

It will be nice if you can take a screenshot of your storyboard.

KlimczakM
  • 12,576
  • 11
  • 64
  • 83
suleymancalik
  • 307
  • 3
  • 13
0

It's possible to read what's what's happening from the errors: Your label and otherView under it are attached to mysteryView, the label 8 off the top, then 20 separating otherView, and 8 from the bottom of otherView to mysteryView. Very standard. However, an autoresizingMask is setting mysteryView to height of zero. Since it can't satisfy both, it breaks the constraint holding otherView to the bottom. MysteryView goes to zero height (but apparently staying at the top position) and the Label goes 8 off of that, etc., until the otherView hangs attached to nothing at the bottom.

Since mysteryView is attached to your UILabel and otherView, it should be possible to find it and/or break the constraints. Find the label that gets the text "Toz Kat Elek >30" and look at its Size Inspector (the ruler icon in the right-hand panel). Find the constraint that attaches to its top space by -8. There could be more than one, which would be part of the problem. Double click it, and it will be highlighted in the Document Outline to the left of the IB window and the constraints details will appear in the inspector.

If you can only find views you're expecting attached to the UILabel and other elements, examine those views. You might want to clear all constraints using the button at the bottom and start over.

However, if you've found mysteryView and it is indeed a stowaway (apparently with a height of zero) then delete it. The constraints attached to your label and view were working, so you might need to add new ones, attaching the top and bottom to the real top and bottom superview.

Mike Sand
  • 2,750
  • 14
  • 23
0

have you tried removing the bottom margin contraint for the UIView ?, for what you posted on the warning it says it's removing it to recover from the error. If you did it already can you post the view hierarchy but with the constraints opened? .