title: UICollectionView cell layout is out of the collection view's bounds
body: <p>I have a UICollectionView which lays its cells out using Flow Layout. It is vertically scrolling.</p>
  
  <p>It fills a 320x480 screen and displays a custom UICollectionViewCell which is always 96*96 - the size is set in Interface Builder and the delegate does not implement methods to set the item size on a per item basis.</p>
  
  <p>There are insets on the left and right which are 10 px each and the minimum spacing is set to 6px.</p>
  
  <p>What happens therefore is 3 cells per horizontal line. </p>
  
  <p>&lt;-10->&lt;----96---->&lt;-6->&lt;----96---->&lt;-6->&lt;----96---->&lt;-10-> = 320. </p>
  
  <p>The problem that I am having is that occasionally it lays 4 cells on one line!
  The 4th cell is mostly off the screen. It then lays only 2 cells out on the following line to compensate. The whole point of flow layout is that it is a line-breaking layout which should not put anything off-screen!</p>
  
  <p>I have attached a picture:</p>
  
  <p><img src="https://i.stack.imgur.com/NoWtG.png" alt="enter image description here"></p>
  
  <p>Please note that on the second row there is a fourth item mostly off the screen.</p>
  
  <p>I really have no idea what could be causing it. The cells are dynamically filled with data but their size is constant. The cells on all other rows are fitting just fine so there is no reason why on some rows this should happen. </p>
  
  <p>This error occurs at different places each time the collection view is updated. ie. it might happen at row 2 then once an update happens it might happen at row 10 and so on.</p>
  
  <p>The collection view is being updated by a timer. The timer essentially calls a function which processes some data, and then using dispatch_async (onto the main queue) an array containing the backing data is updated and [collectionView reloadData] is called. So I haven't updated the collection view from any thread apart from the main thread. The backing array is only updated on the main queue and in that function; not from anywhere else.</p>
  
  <p>Please could someone give me some suggestions as to what might be going wrong.</p>
  
  <p>Thanks</p>