Marco
Marco

Reputation: 89

Potential Bug in UICollectionview in iOS14

I am encountering a strange behaviour in the way iOS14 handles a CollectionView. I have noticed that (changing from iOS13.5 to iOS14) the order in which the UICollectionViewCells are displayed is wrong. The pictures below are screenshot from exactly the same code (in xCode12), the only difference is that the correct ones are with a build for iOS13.5 and from a simulator with an iPhone 11 on iOS13.5, while the wrong ones are with a build for iOS14 and from a simulator with an iPhone 11 on iOS14. Everything else (code, settings, etc) is exactly the same:

Picture 1, how the collection should display (correct in iOS13.5):

enter image description here

If the same code is built with iOS14 and run on the same iPhone simulator with iOS14, the result is the following (not the order is wrong: it is reversed):

In the datasource (which is an array with the labels) all is correct and the cellForItemAt delegate works correctly.

There is definitely something being handled differently in iOS14. One last example is another screenshot where the sizes of the boxes are different (depending on the length of the labels):

Correct (building for iOS13.5) is:

enter image description here

While building for iOS14 yields the following:

enter image description here

Again, the code is exactly the same, I am just building the project for different iOS versions. It seems to me there may be a bug somewhere in the way collections have been modified for iOS14. Any help or thought would be welcome.

Upvotes: 2

Views: 1217

Answers (1)

Marco
Marco

Reputation: 89

I have found how to solve this, and I think it points to some changes in how the management of the delegates for UICollectionView in iOS14 may have taken place.

The solution is simple: I have just added

cell.setNeedsDisplay()

in

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath)

before returning the cell.

No other change to the code. I noticed that in iOS14 draw() for the cell was not called as in iOS13.5. Thus adding the setNeedsDisplay() forced the redraw of the cell, which in iOS13.5 was happening without the new line of code.

I would be interested to know if anybody knows of any change. Thanks

Upvotes: 1

Related Questions