UICollectionView crashes animating changes when header is included

Originator:rcritz
Number:rdar://13358414 Date Originated:3/6/2013
Status:Open Resolved:
Product:iPhone SDK Product Version:6.1
Classification:crash Reproducible:always
 
Summary: When using a UICollectionView with a header, attempting to insert a cell at indexPath [0,0] results in an application crash. Additionally, attempting to remove the last cell from a view will result in a similar crash.

Steps to Reproduce: See the attached sample code.  Build and run, press "Add" and the crash will happen about 50% of the time. If it does not crash, stop the simulator, "Clean" the build and run again. Within 3 tries (usually on the first try for me), the crash will appear.  The second form of the crash can be demonstrated in the attached code by pressing "Preload" and then "Remove". If the crash doesn't appear, the same "clean" and "run" recycle will bring it out.

Expected Results: Cells appear and disappear in the collection view as requested.

Actual Results: Application crashes with a message similar to:

2013-03-06 11:41:35.896 CollectionViewBugDemo[15345:c07] *** Assertion failure in -[UICollectionViewData indexPathForItemAtGlobalIndex:], /SourceCache/UIKit_Sim/UIKit-2380.17/UICollectionViewData.m:442
2013-03-06 11:41:35.898 CollectionViewBugDemo[15345:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for index path for global index 1610612735 when there are only 1 items in the collection view'

Please note that the value for the global index reported in the message above changes from crash to crash.

Regression: I've only tested this on iOS 6.1.

Notes: The only workaround I've found is to remove the animation (i.e. stop calling insertItemsAtIndexPaths and deleteItemsAtIndexPaths) and call reloadData instead. The only alternative for retaining the animations is to remove the header.


Additional note just for openradar: sample code is at https://www.dropbox.com/s/o4fm6whhvmz4yy9/CollectionViewBugDemo.zip

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!