1
votes

I have a UICollectionViewCell in storyboard that has a UIImageView inside of it.

The UICollectionViewCell size is width: 189, height: 239 . The ImageView has the following constraints:

Trailing Space to cell = 31
Leading Space to cell = 31
Bottom Space to cell =  25
Top Space to cell = 31

I receive the following error when running:

2014-11-28 19:53:33.934 AppName[1585:35698] 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:0x7fa4a0d75220 H:[UIImageView:0x7fa4a0d743e0]-(31)-|   (Names: '|':UIView:0x7fa4a0d73d40 )>",
"<NSLayoutConstraint:0x7fa4a0d752c0 H:|-(32)-[UIImageView:0x7fa4a0d743e0]   (Names: '|':UIView:0x7fa4a0d73d40 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7fa4a0d567a0 h=--& v=--& H:[UIView:0x7fa4a0d73d40(50)]>" )

Will attempt to recover by breaking constraint NSLayoutConstraint:0x7fa4a0d75220 H:[UIImageView:0x7fa4a0d743e0]-(31)-| (Names: '|':UIView:0x7fa4a0d73d40 )>

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

I tried changing the leading/trailing values in all kinds of ways (tried even/odd numbers) with no success. What is causing this?

1
Does it show you the list of constraints and tell you which one it's trying to break? If so, post that information. - rdelmar
updated question, stackoverflow's formatting caused certain text to not appear - CaptainCOOLGUY
That last constraint is saying that the view, UIView:0x7fa4a0d73d40, which presumably is your cell, has a width of 50. What size are you returning for your cell in the collection view's data source? - rdelmar
Weirdly I do not modify the size of the cell in any datasource methods, I only had set the width/height of the cell in storyboard. I added the collectionView to a VC using self.collectionViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) if that makes a difference. - CaptainCOOLGUY
I only implement func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { - CaptainCOOLGUY

1 Answers

6
votes

This is a known bug in iOS 8 (see this post, Autoresizing issue of UICollectionViewCell contentView's frame in Storyboard prototype cell (Xcode 6, iOS 8 SDK) happens when running on iOS 7 only). The cell is the correct size that you set in the storyboard, but the cell's content view's size is staying at 50x50, which is why you get the constraint error. It can be fixed by adding this line after you create the cell in cellForItemAtIndexPath:,

cell.contentView.frame = cell.bounds