1

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?

CaptainCOOLGUY
  • 1,131
  • 1
  • 14
  • 26
  • Does it show you the list of constraints and tell you which one it's trying to break? If so, post that information. – rdelmar Nov 29 '14 at 01:13
  • updated question, stackoverflow's formatting caused certain text to not appear – CaptainCOOLGUY Nov 29 '14 at 01:17
  • 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 Nov 29 '14 at 01:21
  • 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 Nov 29 '14 at 01:24
  • 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 Nov 29 '14 at 01:26
  • I don't know what to say. There's nothing wrong with the constraints you added. They should work, if the cell is big enough, that those constraints make sense. Does your cell look like its 189x239 when you run the app? – rdelmar Nov 29 '14 at 01:27
  • Yes it does. I just tried lowering the priority on the trailing constraint to 999 and no longer is xcode complaining.. That just means my trailing constraint is being adjusted to a new number right? – CaptainCOOLGUY Nov 29 '14 at 01:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/65862/discussion-between-rdelmar-and-captaincoolguy). – rdelmar Nov 29 '14 at 01:29

1 Answers1

6

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
Community
  • 1
  • 1
rdelmar
  • 103,982
  • 12
  • 207
  • 218