7

Since iOS 9 launched, Crashalytics has reported a fair number of crashes from NSInternalInconsistencyException:UICollectionViewdata source is not set even when the data source is set. It feels like it might be an SDK bug, but I have no idea how to avoid it.

Details:

  • This only happens on iOS 9. Hundreds of occurrences on iOS 9, zero on 7/8
  • This happens on the main thread, deep in UIKit code
  • I am setting the DataSource, but it looks like the UICollectionView is outliving the DataSource?
  • No consistent repro, but it happens many times a day according to Crashalytics.
Thread : Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x181a91900 __exceptionPreprocess
1  libobjc.A.dylib                0x1810fff80 objc_exception_throw
2  CoreFoundation                 0x181a917d0 +[NSException raise:format:]
3  Foundation                     0x18240499c -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4  UIKit                          0x1869152dc -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:]
5  UIKit                          0x1867e8990 -[UICollectionView _updateVisibleCellsNow:]
6  UIKit                          0x1867e389c -[UICollectionView layoutSubviews]
Sagar Chauhan
  • 5,715
  • 2
  • 22
  • 56
scosman
  • 2,343
  • 18
  • 34
  • 1
    *"it looks like the UICollectionView is outliving the datasource"*… this is entirely possible if you are not ensuring the data source is retained. The collection view will not retain it for you. – Aaron Brager Jan 29 '16 at 00:24
  • @AaronBrager I should have mentioned: the datasource is the ViewController, which is the only thing retaining the collection view. – scosman Jan 29 '16 at 00:25
  • Is it possible you're later un-setting the data source? Or that your view controller is being deallocated? – Aaron Brager Jan 29 '16 at 00:45
  • have no problem with it. I think your dataSource is not valid, you should try reproduce – Wingzero Jan 29 '16 at 01:00
  • @Wingzero what do you mean not valid? It works fine. It's possible my app is just higher traffic, so I see more occurrences of a rare bug (it only happens once every 50k sessions or so). – scosman Jun 21 '16 at 15:12
  • @AaronBrager just triple checked. Definitely not unsetting it anywhere. The only time I touch it is `.datasource = self` in the init function. – scosman Jun 21 '16 at 15:13
  • you still have the issue for over 3 months? I don't see this happens on my side at all, for iOS 9. Anyway, you should google "UICollectionView dataSource is not set" then – Wingzero Jun 21 '16 at 22:37
  • 2
    @Wingzero thanks for the tip, I never would have thought of that! – scosman Jun 21 '16 at 22:53
  • 1
    @delrox we're seeing the same thing on ios9. It's very hard to reproduce, it happens when the view is animated off the navigation controller stack via the 'back' button. – cthomaschase Jun 21 '16 at 23:48
  • 1
    Did you ever solve this? I am getting the same error, but only when I test on my iPad mini which has iOS 9.3.5. I don't get this error on any iPhones, but that could be because they all run iOS 10+. – Coder1224 Jan 15 '17 at 21:09
  • I got this error when I set footerHeight in ios9 – Voora Tarun Jul 25 '17 at 10:07

0 Answers0