Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange autolayout behaviour on collection views

I have an issue with autolayout, the console is reporting problems with an image view I have in a cell:

RefreshCatalogue[31754:16177989] 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:0x7fa98103b740 V:[UIImageView:0x7fa9810375d0]-(0)-|   (Names: '|':UIView:0x7fa9810371d0 )>",
    "<NSLayoutConstraint:0x7fa98103b7e0 V:|-(0)-[UIImageView:0x7fa9810375d0]   (Names: '|':UIView:0x7fa9810371d0 )>",
    "<NSLayoutConstraint:0x7fa98103b8d0 UIImageView:0x7fa9810375d0.centerY == UIImageView:0x7fa981037490.centerY>",
    "<NSLayoutConstraint:0x7fa98103ba60 UIImageView:0x7fa981037490.top == UIView:0x7fa9810371d0.topMargin + 71>",
    "<NSAutoresizingMaskLayoutConstraint:0x7fa980d44a10 h=--& v=--& V:[UIView:0x7fa9810371d0(50)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fa98103b8d0 UIImageView:0x7fa9810375d0.centerY == UIImageView:0x7fa981037490.centerY>

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 problem is that if I do:

[self.collectionView reloadItemsAtIndexPaths:@[indexPath]];

Nothing shows even tho the image view seems to have correct frame, the image property is set. If I reload the entire collection view with:

[self.collectionView reloadData];

The error is still there but the image shows. The code is open here shall anyone be interested in taking a look: https://github.com/Ridiculous-Innovations/RefreshCatalogue

Also, all the constraints in the story board seem to be in blue. Any idea what might be causing the issue?

Edit: Needless to say that all the elements, including the image view are on the right place (I did debug frames and set random colours) but the image didn't display till refresh ... sometimes the cells don't display at all

like image 726
Ondrej Rafaj Avatar asked Aug 17 '15 12:08

Ondrej Rafaj


Video Answer


1 Answers

You have issue with UIImageView:0x7fa981037490.top == UIView:0x7fa9810371d0.topMargin + 71 and parent frame with 0 height (so imageview height must be negative, but this is not allowed), like right after calling dequeueReusableCell method. Possible workaround for this case is change priority from 1000 to 999 on the most bottom constraint in nested view (Vertical Space - catalogueHeaderCell - Image View and Vertical Space - catalogueCell - Info View).

like image 139
pcholberg Avatar answered Oct 14 '22 13:10

pcholberg