Note that there are some explanatory texts on larger screens.

plurals
  1. POUICollectionView flowLayout not wrapping cells correctly (iOS)
    primarykey
    data
    text
    <p>I have a <code>UICollectionView</code> with a FLowLayout. It will work as I expect most of the time, but every now and then one of the cells does not wrap properly. For example, the the cell that should be on in the first "column" of the third row if actually trailing in the second row and there is just an empty space where it should be (see diagram below). All you can see of this rouge cell is the left hand side (the rest is cut off) and the place it should be is empty. </p> <p>This does not happen consistently; it is not always the same row. Once it has happened, I can scroll up and then back and the cell will have fixed itself. Or, when I press the cell (which takes me to the next view via a push) and then pop back, I will see the cell in the incorrect position and then it will jump to the correct position.</p> <p>The scroll speed seems to make it easier to reproduce the problem. When I scroll slowly, I can still see the cell in the wrong position every now and then, but then it will jump to the correct position straight away.</p> <p>The problem started when I added the sections insets. Previously, I had the cells almost flush against the collection bounds (little, or no insets) and I did not notice the problem. But this meant the right and left of the collection view was empty. Ie, could not scroll. Also, the scroll bar was not flush to the right.</p> <p>I can make the problem happen on both Simulator and on an iPad 3.</p> <p>I guess the problem is happening because of the left and right section insets... But if the value is wrong, then I would expect the behavior to be consistent. I wonder if this might be a bug with Apple? Or perhaps this is due to a build up of the insets or something similar...</p> <p>Any solutions/workarounds are appreciated.</p> <p><img src="https://i.stack.imgur.com/kNVYs.png" alt="Illustration of problem and settings"></p> <hr> <p><strong>Follow up</strong>: I have been using <a href="https://stackoverflow.com/a/13389461/377384">this answer</a> below by Nick for over <s>6 months</s> <s>12 months</s> 2 years now without a problem (in case people are wondering if there are any holes in that answer - I have not found any yet). Well done Nick.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload