Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode Interface Builder 9.1 Collection View Cells have too small "expected height"

Recently, I encountered a problem with the Interface Builder which I failed to solve. I'm using a UICollectionViewController and whenever I add a Cell it immediately shows a orange rectangle (indicating a auto-layout update). Updating the frame/cell doesn't change anything. The warning associated with the orange marking reads "Expected: height=Y, Actual: height=X" where Y is always exactly X-100. That is: When I set a custom cell height of 193, it says "Expected: height=93". This happens no matter which size I enter.

The problem with this is that I have many difficulties with the subviews and their constraints. For instance, if I add a subview with the constraint to keep the same height as the cell, it will be shown as 93 (the expected height), even though my cell should be 193. Layouting becomes impossible.

I tried adding a new cell, same issue. I tried removing every subview and re-adding them, nothing.

Any ideas are highly welcome.

Thank you very much!

like image 870
Dr. Cashberg Avatar asked Nov 20 '17 20:11

Dr. Cashberg


3 Answers

I'm not sure if this solved it, but the warning and issue disappeared once I did the following:

Select the CollectionViewController in Interface Builder and set the size to freeform and make the height larger, large enough to show all your template cells. (Plus: maybe refresh the views). That solved the issue for me.

like image 33
Dr. Cashberg Avatar answered Oct 07 '22 19:10

Dr. Cashberg


Solution found ! (Xcode 9.2)

The bug seems to only happen when you try to embed the UICollectionViewController in a Container View in the storyboard. The workaround is to remove the segue while you set your constraints, and re-add the segue once your constraints are well set.

I also think that setting UICollectionViewController size as Freeform could be responsible of the bug. If so, try to set constraints before changing the size.

Hope this helps !

like image 152
AnthoPak Avatar answered Oct 07 '22 17:10

AnthoPak


In my case, I have added two collection view cell, withing collection view Controller.Only setting the view controller to free form wont help us. Need to update the size, to get rid of the warning.

updating collection view cell frames, wont help us. Warning will be continuously changing its length.

Get rid of story board warning

I tried to work without considering the warning, as I have set my collection view cell size programmatically and it does working as expected.

like image 29
Sujananth Avatar answered Oct 07 '22 17:10

Sujananth