6

I have a UICollectionView which lays its cells out using Flow Layout. It is vertically scrolling.

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.

There are insets on the left and right which are 10 px each and the minimum spacing is set to 6px.

What happens therefore is 3 cells per horizontal line.

<-10-><----96----><-6-><----96----><-6-><----96----><-10-> = 320.

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!

I have attached a picture:

enter image description here

Please note that on the second row there is a fourth item mostly off the screen.

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.

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.

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.

Please could someone give me some suggestions as to what might be going wrong.

Thanks

4

1 回答 1

1

我通过添加委托方法[_collectionViewFlowLayout invalidateLayout]来修复它。scrollViewDidScroll:

https://github.com/f33chobits/FSCalendar/issues/21

于 2015-04-16T22:47:05.830 回答