Shawn
Shawn

Reputation: 667

Prototyped collection view cell "Unable to simultaneously satisfy constraints." warning

I am using storyboards in my application and I have prototyped my cell with constraints. However, I want to size my cell based on the screen size so I am giving them a size using this callback method:

- (CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(self.photosCollectionView.frame.size.width-15, self.photosCollectionView.frame.size.width+40);
}

When I do this it gives the big warning "Unable to simultaneously satisfy constraints" which is in a lot of posts on stack. I have tried a lot of things I have read such as removing the constraints using [cell.contentview setTranslatesAutoresizingMaskIntoConstraints:NO]; but then my cell subviews end up all over the place. Please if anyone has any suggestions let me know. Thank you!

Upvotes: 1

Views: 763

Answers (1)

Shawn
Shawn

Reputation: 667

had to do this when I dequeue the cell:

[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
[cell layoutIfNeeded];

Upvotes: 1

Related Questions