UICollectionView crashes on scrollToItemAtIndexPath:atScrollPosition:Animated

Originator:bstovold
Number:rdar://13416281 Date Originated:06/03/2013
Status:Closed Resolved:7.x
Product:iOS Product Version:6.1.x
Classification:Serious Bug Reproducible:Always
 
- Steps to Reproduce or other supporting screenshots, logs, etc: 

1. Download the Xcode project from https://www.dropbox.com/sh/sqh61lwp8c6jrva/Im2wPDygJ7. Open, build and run
2. Tap on first cell in tableViewController

Expected Outcome:
3. Same as tapping on second cell, i.e. view is pushed and UICollectionViewInstance scrolls to the last index OR a more helpful assertion log message is displayed.

Actual Outcome:
3. App Crashes with the following log message:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'must return a UICollectionViewLayoutAttributes instance from -layoutAttributesForItemAtIndexPath: for path <NSIndexPath 0x76549a0> 2 indexes [0, 2]'

It seems that UIKit returns this assertion message whenever -scrollToItemAtIndexPath:atScrollPosition:Animated is called when the UICollectionView is not yet laid out. If UICollectionView needs have laid out it's subviews before it is scrolled programmatically, it would be much more helpful if the error message said as much, as this is quite a difficult problem to debug unless you know what you're looking for.

Comments

Repro'd the issue.

Seconding this - the assertion doesn't make any sense, especially when you're using the built-in flow layout.


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!