0

我真的一直在努力解决这个 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 被初始化为正确的类
  2. TableView 连接到 UITableViewController
  3. 我已经检查了我能找到的每个插座,以确保没有任何错误连接或空连接。

非常感谢您的帮助,万分感谢!

4

2 回答 2

1

dequeueReusableCellWithIdentifier正在尝试EventTableViewCell从 a实例化一个.xib听起来该文件包含一个无效绑定,该绑定试图viewEventTableViewCell. 在 Xcode 中查看您的 xib,您可能会收到有关无效插座绑定的警告。

于 2016-07-08T23:35:41.433 回答
1

您应该在 nib/storyboard 中选择 tableview 单元格并在实用程序面板中检查 Outlets。如果单元格出现任何损坏的插座 Xcode 将在连接节点上放置爆炸标记。要查找 xib/storyboard,您应该使用 EventTableViewCell 在 xcode 中搜索

于 2016-07-08T23:45:34.263 回答