How can I fix the "misplaced views" warning of collection view elements in Xcode 9?
Asked Answered
S

4

10

So I use Xcode 9.2, for a month I didn't have this problem working on the project. Today, I remember I changed the navigation bar to be "NOT" translucent in the storyboard. After I unchecked it, these two warnings appeared.

I have read and done many solutions suggested in here and other websites, but it's still there. I haven't found the solution for issues happening on Xcode 9 though. The fixes Xcode give (I tried to update constraints and reset to suggested constraints) do nothing if the "fix misplacement" is clicked.

section header and cell of collection view - misplaced views warning

I have set the heights through the storyboard.
I have set the heights through the code as well but still no luck. And there is no problem at all on the app after running it.

I wonder if this a bug, which I read happening in Xcode 8 and earlier, or there is just a simple fix in Xcode 9 which I don't know.
I haven't found anyone having this problem in Xcode 9, so I give a shot to ask. Any help is really appreciated.

Thank you in advance!

Subjection answered 10/12, 2017 at 21:43 Comment(1)
Something similar is happening to me right now as well. I can update frames and make it go away, but when I "view as:" a different device the warning comes back. Very annoying.Yttriferous
I
5

This seems to be a bug in Interface Builder. A possible (although not permanent) fix is changing the screen size used for the preview.

Click on the View as: section at the bottom of Interface Builder and change the device to another. You can revert to the original device afterwards.

"View as:" section in Interface Builder

Indo answered 11/12, 2017 at 13:8 Comment(4)
I tried to change the screen size as you mentioned but the warning were still there. However, I unchecked the Use Auto Layout option then the warnings disappeared. The problem is all my view controllers are now not using the Auto Layout. So this is a bug then..?Subjection
@SwiftMage This is, indeed, a bug. Try to clean the project folder/erase Derived Data and restart Xcode.Blais
I did, several times. I erased the the derived folders, cleaned the project, closed and reopened it, and cleaned it again, still no luck. The warnings disappeared only if I turned off the Auto Layout. Well I guess I have to make peace with it. :(Subjection
I had this bug in XCode 10.1 and solution of Tamas helped me.Mccarthy
A
6

For anyone looking for a temporary workaround, you may

  1. Select the cell with problem
  2. Open the Size Inspector (on right hand side)
  3. Change the dropdown Size from Default to Custom
  4. increase / decrease height or width by 1
  5. reverse 3. and back to the desired dimension

See if the above makes the warning disappear.

Astraddle answered 17/10, 2018 at 10:36 Comment(2)
This works on XCode 10 - the bug seems to still be an issue.Ewart
This works on Xcode 10.1, looks like they will not fix that soon.Cytherea
I
5

This seems to be a bug in Interface Builder. A possible (although not permanent) fix is changing the screen size used for the preview.

Click on the View as: section at the bottom of Interface Builder and change the device to another. You can revert to the original device afterwards.

"View as:" section in Interface Builder

Indo answered 11/12, 2017 at 13:8 Comment(4)
I tried to change the screen size as you mentioned but the warning were still there. However, I unchecked the Use Auto Layout option then the warnings disappeared. The problem is all my view controllers are now not using the Auto Layout. So this is a bug then..?Subjection
@SwiftMage This is, indeed, a bug. Try to clean the project folder/erase Derived Data and restart Xcode.Blais
I did, several times. I erased the the derived folders, cleaned the project, closed and reopened it, and cleaned it again, still no luck. The warnings disappeared only if I turned off the Auto Layout. Well I guess I have to make peace with it. :(Subjection
I had this bug in XCode 10.1 and solution of Tamas helped me.Mccarthy
L
2

I was getting a continuous "misplaced views" warning on my Collection View Cell.

It said "Expected: width = 0, height = 0"

I got the warning to go away by dragging the corners of it to be size 0,0 on the storyboard. I can't see the cell now, but I don't have a bothersome warning either.

Liquidate answered 2/7, 2018 at 15:15 Comment(3)
Has anyone been able to get this resolved!? I get the same issue!?Fogel
That's just giving in to the problem. The auto layout engine is supposed to resize the cell and its contents when we change the constraints, so we an see what it looks like.Farica
I understand that this isn't a solution. However, if the accepted answer is true (that it's a bug in Interface Builder), then I'm just offering up what I did to get rid of the annoying warning, while we wait for Apple to fix the bug. Hopefully, Xcode 10 has fixed this...Liquidate
U
0

If none of the above solutions don't work for you try this:

  1. Right click on .xib file -> Open As -> Source Code
  2. CMD + F -> search for: misplaced="YES"
  3. remove any instances
  4. Right click on .xib file -> Open As -> Interface Builder
  5. run the project again and see if the warning persists

This was the only solution that worked for me in Xcode 13.4.

Hope this helps someone!

Use answered 24/5, 2022 at 14:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.