NSLayoutConstraint Unable to simultaneously satisfy constraints

1

I'm trying to customize my own'UilollectionViewCell' and doing so using constraints gives me the following error:

2016-05-28 17:33:44.843 CollectionView[11392:2736021] 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) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x7f8b5a527340 h=--& v=--& H:[UILabel:0x7f8b5a5262a0'Ola ola ola'(0)]>",
    "<NSLayoutConstraint:0x7f8b5a526720 UILabel:0x7f8b5a5262a0'Ola ola ola'.width == CollectionView.CollectionViewCell:0x7f8b5a51c050.width + 40>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f8b5a526720 UILabel:0x7f8b5a5262a0'Ola ola ola'.width == CollectionView.CollectionViewCell:0x7f8b5a51c050.width + 40>

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.
2016-05-28 17:33:44.868 CollectionView[11392:2736021] 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) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x7f8b5a5273e0 h=--& v=--& V:[UILabel:0x7f8b5a5262a0'Ola ola ola'(0)]>",
    "<NSLayoutConstraint:0x7f8b5a526770 UILabel:0x7f8b5a5262a0'Ola ola ola'.height == CollectionView.CollectionViewCell:0x7f8b5a51c050.height + 40>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f8b5a526770 UILabel:0x7f8b5a5262a0'Ola ola ola'.height == CollectionView.CollectionViewCell:0x7f8b5a51c050.height + 40>

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.
init frame decoder
2016-05-28 17:33:44.870 CollectionView[11392:2736021] 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) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x7f8b5a732fd0 h=--& v=--& H:[UILabel:0x7f8b5a71dc60'Ola ola ola'(0)]>",
    "<NSLayoutConstraint:0x7f8b5a716de0 UILabel:0x7f8b5a71dc60'Ola ola ola'.width == CollectionView.CollectionViewCell:0x7f8b5a4b9fa0.width + 40>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f8b5a716de0 UILabel:0x7f8b5a71dc60'Ola ola ola'.width == CollectionView.CollectionViewCell:0x7f8b5a4b9fa0.width + 40>

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.
2016-05-28 17:33:44.870 CollectionView[11392:2736021] 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) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x7f8b5a730730 h=--& v=--& V:[UILabel:0x7f8b5a71dc60'Ola ola ola'(0)]>",
    "<NSLayoutConstraint:0x7f8b5a72dd70 UILabel:0x7f8b5a71dc60'Ola ola ola'.height == CollectionView.CollectionViewCell:0x7f8b5a4b9fa0.height + 40>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f8b5a72dd70 UILabel:0x7f8b5a71dc60'Ola ola ola'.height == CollectionView.CollectionViewCell:0x7f8b5a4b9fa0.height + 40>

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.
init frame decoder
2016-05-28 17:33:44.871 CollectionView[11392:2736021] 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) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x7f8b5a4b7980 h=--& v=--& H:[UILabel:0x7f8b5a4bd070'Ola ola ola'(0)]>",
    "<NSLayoutConstraint:0x7f8b5a403c80 UILabel:0x7f8b5a4bd070'Ola ola ola'.width == CollectionView.CollectionViewCell:0x7f8b5a4a6950.width + 40>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f8b5a403c80 UILabel:0x7f8b5a4bd070'Ola ola ola'.width == CollectionView.CollectionViewCell:0x7f8b5a4a6950.width + 40>

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.
2016-05-28 17:33:44.871 CollectionView[11392:2736021] 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) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x7f8b5a4a81a0 h=--& v=--& V:[UILabel:0x7f8b5a4bd070'Ola ola ola'(0)]>",
    "<NSLayoutConstraint:0x7f8b5a403cd0 UILabel:0x7f8b5a4bd070'Ola ola ola'.height == CollectionView.CollectionViewCell:0x7f8b5a4a6950.height + 40>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f8b5a403cd0 UILabel:0x7f8b5a4bd070'Ola ola ola'.height == CollectionView.CollectionViewCell:0x7f8b5a4a6950.height + 40>

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.

The code for my class is as follows:

class CollectionViewCell: UICollectionViewCell {

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        print("init cell decoder")
        setUp()
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        print("init frame decoder")
        setUp()
    }

    func setUp() {
        //addSubview(detailLabel)
        //addSubview(profileImage)
        let nickLabel = UILabel()
        nickLabel.backgroundColor = UIColor.cyanColor()
        nickLabel.text = "Ola ola ola"

        addSubview(nickLabel)

        self.translatesAutoresizingMaskIntoConstraints = false
       // let imageY = NSLayoutConstraint(item: nickLabel, attribute: .CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1.0, constant: 0)
       // let imageX = NSLayoutConstraint(item: nickLabel, attribute: .Left, relatedBy: .Equal, toItem: self, attribute: .Left, multiplier: 1.0, constant: 20)
        let imageWidth = NSLayoutConstraint(item: nickLabel, attribute: .Width, relatedBy: .Equal, toItem: self, attribute: .Width, multiplier: 1, constant: 40)
        let imageHeight = NSLayoutConstraint(item: nickLabel, attribute: .Height, relatedBy: .Equal, toItem: self, attribute: .Height, multiplier: 1, constant: 40)

        addConstraints([imageWidth,imageHeight])

    }
}

What I try to do, is in the'UICollectionViewCell' add a label on the left (with a margin of 10px) and centered on the'X'. Although in the code I do not do exactly that, I do not understand why I get the error

    
asked by MatiEzelQ 28.05.2016 в 22:39
source

1 answer

0

The error in this code is in the following line:

 self.translatesAutoresizingMaskIntoConstraints = false

This method should not be applied to the view itself, if not, to whom the NSLayoutConstraints of width or height is applied. Then, the line would look like this:

 nickLabel.translatesAutoresizingMaskIntoConstraints = false
    
answered by 30.05.2016 в 21:04