Reputation: 154
I am working on a project that uses storyboards and was started in XCode 6 and has been upgraded to XCode 7. I am trying to add a UICollectionViewController. I get an exception on this line: let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! UnsplashCollectionViewCell
I have verified that the controller and cell are both assigned to my custom class in the storyboard, and that my reuse identifier is assigned to the cell and the same as the variable reuseIdentifier in my controller class.
About the only difference I can tell between a working UICollectionViewController and this project's is if I start a new project and add a UICollectionViewController I get the following in the Connections Inspector:
However, the Connections Inspector in my broken project looks like:
I'm not sure this is the problem, but I'm at a loss for what else it could be.
Crash log:
Uncaught exception: could not dequeue a view of kind: UICollectionElementKindCell with identifier UnsplashCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard
Full Crash Log:
2016-03-14 10:34:55.027 PixelSquidTouch[86881:2845927] [Crashlytics] Version 3.4.1 (92) 2016-03-14 10:34:55.063 PixelSquidTouch[86881:] App measurement v.1201000 started 2016-03-14 10:35:02.990 PixelSquidTouch[86881:2845927] *** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UICollectionView.m:3690 2016-03-14 10:35:03.013 PixelSquidTouch[86881:2845927] WARNING: GoogleAnalytics 3.14 void GAIUncaughtExceptionHandler(NSException *) (GAIUncaughtExceptionHandler.m:48): Uncaught exception: could not dequeue a view of kind: UICollectionElementKindCell with identifier UnsplashCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard 2016-03-14 10:35:08.054 PixelSquidTouch[86881:2845927] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier UnsplashCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard' *** First throw call stack: ( 0 CoreFoundation 0x000000010c95ce65 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010ffb0deb objc_exception_throw + 48 2 CoreFoundation 0x000000010c95ccca +[NSException raise:format:arguments:] + 106 3 Foundation 0x000000010fa274de -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198 4 UIKit 0x000000010ddd04e9 -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] + 2009 5 UIKit 0x000000010ddd0945 -[UICollectionView dequeueReusableCellWithReuseIdentifier:forIndexPath:] + 169 6 PixelSquidTouch 0x000000010b8d9e6a _TFC15PixelSquidTouch32UnsplashCollectionViewController14collectionViewfS0_FTCSo16UICollectionView22cellForItemAtIndexPathCSo11NSIndexPath_CSo20UICollectionViewCell + 122 7 PixelSquidTouch 0x000000010b8d9f8f _TToFC15PixelSquidTouch32UnsplashCollectionViewController14collectionViewfS0_FTCSo16UICollectionView22cellForItemAtIndexPathCSo11NSIndexPath_CSo20UICollectionViewCell + 79 8 UIKit 0x000000010ddc05ba -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:] + 483 9 UIKit 0x000000010ddc2ae0 -[UICollectionView _updateVisibleCellsNow:] + 4431 10 UIKit 0x000000010ddc723b -[UICollectionView layoutSubviews] + 247 11 UIKit 0x000000010d6224a3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703 12 QuartzCore 0x000000010f41759a -[CALayer layoutSublayers] + 146 13 QuartzCore 0x000000010f40be70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366 14 QuartzCore 0x000000010f40bcee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 15 QuartzCore 0x000000010f400475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277 16 QuartzCore 0x000000010f42dc0a _ZN2CA11Transaction6commitEv + 486 17 UIKit 0x000000010d596b47 _afterCACommitHandler + 174 18 CoreFoundation 0x000000010c888367 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 19 CoreFoundation 0x000000010c8882d7 __CFRunLoopDoObservers + 391 20 CoreFoundation 0x000000010c87df2b __CFRunLoopRun + 1147 21 CoreFoundation 0x000000010c87d828 CFRunLoopRunSpecific + 488 22 GraphicsServices 0x000000011197cad2 GSEventRunModal + 161 23 UIKit 0x000000010d56b610 UIApplicationMain + 171 24 PixelSquidTouch 0x000000010b957aad main + 109 25 libdyld.dylib 0x0000000110b5692d start + 1 26 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException
Upvotes: 0
Views: 455
Reputation: 29886
So, you are trying to dequeue a cell but there is no cell with that ID. You need to open the cell in the storyboard or Xib and set the UICollectionElementKindCell
ID to that id UnsplashCell
If you havent done the cell in the storyboard as a prototype cell, but are using a xib file, then you also need to register that cell with the tableview, so it knows about the cell type.
in your viewDidLoad:
let nibName = UINib(nibName: "UICollectionElementKindCell", bundle:nil)
self.tableView.registerNib(nibName, forCellReuseIdentifier: "UnsplashCell")
Update:
Look at the objects outlets etc. in the storyboard with the VC selected.
Upvotes: 1
Reputation:
I am also struggling with this same issue since upgrading to XCode 7 last week. In our case, we were disabling user interaction whenever we displayed an activity view:
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
Then, in a callback block we were re-enabling user interaction with this:
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
Removing these calls resolved three out of four of these issues in our code; hopefully it can fix your issue as well. In any event, we haven't come up with a better approach as of yet.
Upvotes: 0