NSInternalInconsistencyException on -[UICollectionView insertItemsAtIndexPaths:i
I am sporadically receiving an NSInternalInconsistencyException when attempting to insert new items to a UICollectionView. By sporadically, I mean 90% of the time, including when it works fine at first, but subsequent insertions (on the same build & run session) eventually receives an exception (e.g., after 4-5 insertions). I am aware that there is an existing issue with inserting into an empty section, so I have included a workaround (call reloadData instead of insertItemsAtIndexPaths:inSections: for the first insertion).
Steps to Reproduce:
I have two UICollectionViews displayed in a UIViewController via containers: ScheduleViewController and OfficeViewController. Double-tapping on an item in the Schedule collection presents a UIActionSheet with one prompt: Check In. Tapping Check In calls checkInPatientAtIndexPath:, in which the item is removed from the Schedule collection and passed to an NSNotification. OfficeViewController receives that NSNotification, adds the item to the collection data source, and then calls insertItemsAtIndexPaths:inSections:. I am aware that there is an issue with inserting into an empty section, so I have included a workaround (call reloadData instead of insertItemsAtIndexPaths:inSections: for the first insertion). After the first insertion, I get an NSInternalInconsistencyException almost every time. I noticed that, when an exception is about to occur, beforehand [self.collectionView indexPathsForVisibleItems] is empty, whereas when the insertion process is going to be successful, [self.collectionView indexPathsForVisibleItems] returns the expected results.
UICollectionView should have completed insertion animation successfully.
Console output (containing errors or exceptions)
2013-01-03 14:50:23.058 Precise Glance[37294:c07] *** Assertion failure in -[UICollectionViewData indexPathForItemAtGlobalIndex:], /SourceCache/UIKit_Sim/UIKit-2372/UICollectionViewData.m:442
2013-01-03 14:50:23.059 Precise Glance[37294:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for index path for global index 1 when there are only 1 items in the collection view'
*** First throw call stack:
(0x159b012 0x12a8e7e 0x159ae78 0xd3ef35 0x71ff20 0x705669 0x6fe5c6 0x700dc5 0x6fe31b 0x6fad4e 0x6fad86 0x2d3b 0xd69dc9 0x15f50c5 0x154fefa 0xc9e482 0xcb173b 0x5739 0x5c6a 0x5ce982 0x22e3b6 0x22e554 0x86f81f8 0x1067d8 0x23c5014 0x23b57d5 0x1541af5 0x1540f44 0x1540e1b 0x25fc7e3 0x25fc668 0x1f065c 0x235d 0x2285 0x1)
libc++abi.dylib: terminate called throwing an exception
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!