UITableView 在创建单元格时抛出 NSUnkownKeyException

UITableView throwing NSUnkownKeyException on creation of cell

我真的一直在努力修复这个 NSUnkownKeyException 我现在在我的 UITableView 中创建一个单元格。这是导致错误的代码行:

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

实际错误:

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) 

我检查的事情:

  1. TableView 已初始化为正确的 class
  2. TableView 连接到 UITableViewController
  3. 我检查了我能找到的每个插座,以确保没有任何错误连接或空连接。

非常感谢您的帮助,不胜感激!

dequeueReusableCellWithIdentifier 正在尝试从 .xib 实例化 EventTableViewCell 听起来该文件包含试图设置 view [=18 的无效绑定=](不存在)在 EventTableViewCell 上。查看 Xcode 中的 xib,您可能会收到有关无效出口绑定的警告。

你应该 select nib/storyboard 中的 tableview 单元格并检查公用事业中的插座 panel.If 单元格中任何损坏的插座 Xcode 都会给连接加上爆炸标记 node.For 找到 xib/storyboard 你应该用 EventTableViewCell

在 xcode 中搜索