您好我在我的應用程序(storyboard)中添加了一個UITableView
自定義單元格。 現在我想以編程方式添加委託和數據源。如果在viewDidLoad
中添加此代碼,則應用程序崩潰。如果我設置了tableview的代理和數據源,應用程序崩潰
tableView.delegate = self
tableView.dataSource = self
錯誤:
2016-01-30 16:39:29.283 App[4068:880212] Unknown class TableCell in Interface Builder file.
2016-01-30 16:39:29.289 App[4068:880212] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UITableViewCell 0x7fa3a356bb10> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key imgTeam1.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000105302e65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000107042deb objc_exception_throw + 48
2 CoreFoundation 0x0000000105302aa9 -[NSException raise] + 9
3 Foundation 0x00000001056cb9bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
4 UIKit 0x0000000105bd5fd9 -[UIView(CALayerDelegate) setValue:forKey:] + 173
5 UIKit 0x0000000105edcf41 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001052434a0 -[NSArray makeObjectsPerformSelector:] + 224
7 UIKit 0x0000000105edb924 -[UINib instantiateWithOwner:options:] + 1864
8 UIKit 0x0000000105c654f7 -[UITableView _dequeueReusableViewOfType:withIdentifier:] + 428
9 App 0x0000000105112cd9 _TFC6App14ViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 233
10 App 0x00000001051134ff _TToFC6App14ViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 79
11 UIKit 0x0000000105c78e43 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 766
12 UIKit 0x0000000105c78f7b -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
13 UIKit 0x0000000105c4da39 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2996
14 UIKit 0x0000000105c8201c -[UITableView _performWithCachedTraitCollection:] + 92
15 UIKit 0x0000000105c68edc -[UITableView layoutSubviews] + 224
16 UIKit 0x0000000105bd64a3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
17 QuartzCore 0x000000010a08859a -[CALayer layoutSublayers] + 146
18 QuartzCore 0x000000010a07ce70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
19 QuartzCore 0x000000010a07ccee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
20 QuartzCore 0x000000010a071475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
21 QuartzCore 0x000000010a09ec0a _ZN2CA11Transaction6commitEv + 486
22 QuartzCore 0x000000010a09f37c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
23 CoreFoundation 0x000000010522e367 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
24 CoreFoundation 0x000000010522e2d7 __CFRunLoopDoObservers + 391
25 CoreFoundation 0x000000010522384c CFRunLoopRunSpecific + 524
26 UIKit 0x0000000105b1a7cd -[UIApplication _run] + 402
27 UIKit 0x0000000105b1f610 UIApplicationMain + 171
28 App 0x000000010511567d main + 109
29 libdyld.dylib 0x0000000107b4b92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
我希望你知道如何解決這個問題。
你會得到什麼錯誤? –
我在我的問題中添加了錯誤。 – 123
你應該對下面的答案給予反饋。這樣做將幫助我們發現一個可以幫助您的解決方案。如果你參與更多,那麼人們需要時間來幫助你。如果解決方案有幫助並投票,只需添加評論。如果解決方案無法解決問題,請分享有關此問題的更多詳細信息。參與得越多,問答環節就越適合您。 –