UITableView无法将标识符为的单元格出列



我在运行xcode项目时遇到这个问题。我会启动这个项目,模拟器会加载,但一旦加载了应用程序,我就会让它崩溃。这是错误代码:线程1:异常:";无法将标识符为ChecklistItem的单元格出列-必须为该标识符注册一个nib或类,或者在情节提要中连接一个原型单元格";并在终端上说:

2020-07-24 18:11:06.757164+0100 Checklists[983:49709] *** Assertion failure in -[UITableView _dequeueReusableCellWithIdentifier:forIndexPath:usingPresentationValues:], /Library/Caches/com.apple.xbs/Sources/UIKitCore_Sim/UIKit-3920.31.102/UITableView.m:8724
2020-07-24 18:11:06.771044+0100 Checklists[983:49709] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier ChecklistItem - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
*** First throw call stack:
(
0   CoreFoundation                      0x000000010b93ae6e __exceptionPreprocess + 350
1   libobjc.A.dylib                     0x000000010a23a9b2 objc_exception_throw + 48
2   CoreFoundation                      0x000000010b93abe8 +[NSException raise:format:arguments:] + 88
3   Foundation                          0x0000000109c1bbd2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4   UIKitCore                           0x000000010e53d6be -[UITableView _dequeueReusableCellWithIdentifier:forIndexPath:usingPresentationValues:] + 1332
5   UIKitCore                           0x000000010e53d156 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 91
6   Checklists                          0x0000000109979a38 $s10Checklists23ChecklistViewControllerC05tableC0_12cellForRowAtSo07UITableC4CellCSo0jC0C_10Foundation9IndexPathVtF + 264
7   Checklists                          0x0000000109979b25 $s10Checklists23ChecklistViewControllerC05tableC0_12cellForRowAtSo07UITableC4CellCSo0jC0C_10Foundation9IndexPathVtFTo + 165
8   UIKitCore                           0x000000010e556e96 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 867
9   UIKitCore                           0x000000010e520522 -[UITableView _updateVisibleCellsNow:] + 3010
10  UIKitCore                           0x000000010e54024e -[UITableView layoutSubviews] + 194
11  UIKitCore                           0x000000010e8465f4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2478
12  QuartzCore                          0x00000001103b1260 -[CALayer layoutSublayers] + 255
13  QuartzCore                          0x00000001103b73eb _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 523
14  QuartzCore                          0x00000001103c2a8a _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 80
15  QuartzCore                          0x000000011030ba7c _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324
16  QuartzCore                          0x000000011033f467 _ZN2CA11Transaction6commitEv + 649
17  UIKitCore                           0x000000010e3566c3 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 81
18  CoreFoundation                      0x000000010b89eabc __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
19  CoreFoundation                      0x000000010b89e1b3 __CFRunLoopDoBlocks + 195
20  CoreFoundation                      0x000000010b898fa3 __CFRunLoopRun + 995
21  CoreFoundation                      0x000000010b8988a4 CFRunLoopRunSpecific + 404
22  GraphicsServices                    0x0000000114910bbe GSEventRunModal + 139
23  UIKitCore                           0x000000010e33e968 UIApplicationMain + 1605
24  Checklists                          0x000000010997aa1b main + 75
25  libdyld.dylib                       0x000000010c8581fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

根据错误,您在设置表视图时没有注册单元格。

检查文档:

tableView.register(UITableViewCell.self, forCellReuseIdentifier: "DefaultCell")

tableView.register(UINib(nibName: "yourNib", bundle: nil), forCellReuseIdentifier: "CellFromNib")

只需填写cell、nibName、identifier等的正确值……取决于使用的方法

如果你需要更多信息,这里有一个指南链接:链接

最新更新