Ryan Ryan - 5 months ago 22
Swift Question

UITableView throwing NSUnkownKeyException on creation of cell

I have really been struggling to fix this NSUnkownKeyException I am getting now upon creation of a cell in my UITableView. This is the line of code causing the error:

let cell = tableView.dequeueReusableCellWithIdentifier("eventCell", forIndexPath: indexPath) as! EventTableViewCell


ACTUAL ERROR:

2016-07-08 19:08:58.879 myApp[15078:1230258] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<myApp.EventTableViewCell 0x7fbed3811000> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010c143d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010df1fdeb objc_exception_throw + 48
2 CoreFoundation 0x000000010c1439c9 -[NSException raise] + 9
3 Foundation 0x000000010c51519b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
4 UIKit 0x000000010ca264b6 -[UIView(CALayerDelegate) setValue:forKey:] + 173
5 UIKit 0x000000010cd357fb -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x000000010c07d890 -[NSArray makeObjectsPerformSelector:] + 224
7 UIKit 0x000000010cd341de -[UINib instantiateWithOwner:options:] + 1864
8 UIKit 0x000000010cab595f -[UITableView _dequeueReusableViewOfType:withIdentifier:] + 428
9 UIKit 0x000000010cab5e32 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 71
10 myApp 0x000000010a81735a _TFC15firebaseTestApp16CEViewController9tableViewfTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 330
11 myApp 0x000000010a817ccf _TToFC15firebaseTestApp16CEViewController9tableViewfTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 79
12 UIKit 0x000000010cac94f4 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 766
13 UIKit 0x000000010cac962c -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
14 UIKit 0x000000010ca9dd4f -[UITableView _updateVisibleCellsNow:isRecursive:] + 2996
15 UIKit 0x000000010cad2686 -[UITableView _performWithCachedTraitCollection:] + 92
16 UIKit 0x000000010cab9344 -[UITableView layoutSubviews] + 224
17 UIKit 0x000000010ca26980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
18 QuartzCore 0x0000000111a60c00 -[CALayer layoutSublayers] + 146
19 QuartzCore 0x0000000111a5508e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
20 QuartzCore 0x0000000111a54f0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
21 QuartzCore 0x0000000111a493c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
22 QuartzCore 0x0000000111a77086 _ZN2CA11Transaction6commitEv + 486
23 QuartzCore 0x0000000111a777f8 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
24 CoreFoundation 0x000000010c068c37 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
25 CoreFoundation 0x000000010c068ba7 __CFRunLoopDoObservers + 391
26 CoreFoundation 0x000000010c05e7fb __CFRunLoopRun + 1147
27 CoreFoundation 0x000000010c05e0f8 CFRunLoopRunSpecific + 488
28 GraphicsServices 0x000000010f218ad2 GSEventRunModal + 161
29 UIKit 0x000000010c96bf09 UIApplicationMain + 171
30 myApp 0x000000010a834bf2 main + 114
31 libdyld.dylib 0x000000010e9fa92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)


Things i checked:


  1. TableView is initialized to the proper class

  2. TableView is connected to UITableViewController

  3. I have checked every outlet I could find to make sure there were not any misconnections or empty connections.



Thank you so much for help, all is appreciated!

Answer

dequeueReusableCellWithIdentifier is attempting to instantiate an EventTableViewCell from a .xib it sounds like that file contains an invalid binding which is attempting to set a view property (which does not exist) on the EventTableViewCell. Look at your xib in Xcode, you probably have warnings about invalid outlet bindings.