UICollectionView does not properly reuse supplementary views

Originator:zacwest
Number:rdar://21401502 Date Originated:16-Jun-2015 07:04 AM
Status:Open Resolved:
Product:iOS SDK Product Version:
Classification: Reproducible:
 
Summary:
When UICollectionView is inserting several items at once, it sometimes does not invoke the UICollectionViewDataSource method to update the supplementary views (-collectionView:viewForSupplementaryElementOfKind:atIndexPath:) but instead continues to display them on-screen.

This is a complicated problem to explain, so I've attached a sample project as well to demonstrate. In the sample project, you'll find that I have a custom layout like:

(Supplementary) (Cell) (Supplementary)

All 3 are updated to the same text/background color value, so you can quickly visually inspect for errors. You'll note an error in the sample project is that the cell will be updated to a correct value, but not its supplementary views (see attached: example_error.png; the "ZZZZ" row's supplementary views are not correct).

This happens in iOS 8.3 and iOS 9.0. In iOS 8, the sample project does *not* alert, because grabbing supplementary views is harder, but since iOS 9 added a method for it, this sample project is a lot easier to demonstrate there.

Note: this alert might happen even if nothing is visually wrong because the views are coincidentally representing the right type. Hit start again and it'll happen quickly.

Press the "play" bar button item in the sample project to begin.

Steps to Reproduce:
1. Have a UICollectionViewLayout subclass which uses supplementary views per index path.
2. Insert multiple items at once into the collection view.
3. Note the supplementary views do not update properly sometimes.

Expected Results:
The supplementary views always have the UICollectionViewDataSource method invoked when they are being placed on-screen.

Actual Results:
The supplementary views are reused without invoking the UICollectionViewDataSource method.

Version:
Xcode 7.0 beta (7A120f), Xcode 6.3.1 (6D1002)

Notes:
This is a complicated sample project, so if you have any questions, please let me know. It was a bit difficult to distill my main project into this sample project, but I have been battling this issue since before iOS 8.3 came out. My workarounds (never inserting index paths less-than the current maximum item) don't let me use UICollectionView to its full potential.

Configuration:
iOS simulator, iPhone 6, iPod Touch

Attachments:
'CollectionViewSupplementaryViewReuse.zip' and 'example_error.png' were successfully uploaded.


Attachments available at https://bitbucket.org/zacwest/collectionviewsupplementaryviewreuse

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!