Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting UITableView error "unable to dequeue a cell with identifier cell"

I am creating an app with a UITableViewController but I am getting the error:

'unable to dequeue a cell with identifier cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

I don't understand how I to find the solution and fix it.

2018-09-15 01:28:28.609848+0300 Yemekler[6554:482441] *** Assertion failure in -[UITableView _dequeueReusableCellWithIdentifier:forIndexPath:usingPresentationValues:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3698.54.4/UITableView.m:7879
2018-09-15 01:28:28.613237+0300 Yemekler[6554:482441] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000112f461e6 __exceptionPreprocess + 294
    1   libobjc.A.dylib                     0x000000010f3ac031 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000112f4b472 +[NSException raise:format:arguments:] + 98
    3   Foundation                          0x000000010ee4f652 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
    4   UIKit                               0x000000010fd8a496 -[UITableView _dequeueReusableCellWithIdentifier:forIndexPath:usingPresentationValues:] + 879
    5   UIKit                               0x000000010fd8a0f3 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 91
    6   Yemekler                            0x000000010ea9de72 _T08Yemekler17YemekTarifleriTVCC9tableViewSo07UITableF4CellCSo0gF0C_10Foundation9IndexPathV12cellForRowAttF + 226
    7   Yemekler                            0x000000010ea9e34c _T08Yemekler17YemekTarifleriTVCC9tableViewSo07UITableF4CellCSo0gF0C_10Foundation9IndexPathV12cellForRowAttFTo + 92
    8   UIKit                               0x000000010fda5567 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 783
    9   UIKit                               0x000000010fda5ae4 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
    10  UIKit                               0x000000010fd6ceaa -[UITableView _updateVisibleCellsNow:isRecursive:] + 3168
    11  UIKit                               0x000000010fd8d7e0 -[UITableView layoutSubviews] + 176
    12  UIKit                               0x000000010fd177a8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1515
    13  QuartzCore                          0x00000001166b5456 -[CALayer layoutSublayers] + 177
    14  QuartzCore                          0x00000001166b9667 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 395
    15  QuartzCore                          0x00000001166400fb _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 343
    16  QuartzCore                          0x000000011666d79c _ZN2CA11Transaction6commitEv + 568
    17  UIKit                               0x000000010fc62269 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 141
    18  CoreFoundation                      0x0000000112ee8b0c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    19  CoreFoundation                      0x0000000112ecd2db __CFRunLoopDoBlocks + 331
    20  CoreFoundation                      0x0000000112ecca84 __CFRunLoopRun + 1284
    21  CoreFoundation                      0x0000000112ecc30b CFRunLoopRunSpecific + 635
    22  GraphicsServices                    0x000000011583ea73 GSEventRunModal + 62
    23  UIKit                               0x000000010fc48057 UIApplicationMain + 159
    24  Yemekler                            0x000000010ea9c077 main + 55
    25  libdyld.dylib                       0x0000000114127955 start + 1
    26  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
like image 914
dogabalkis Avatar asked Oct 23 '25 16:10

dogabalkis


2 Answers

You need to register the table with a cell before dequeue in viewDidLoad with xib

tableView.register(UINib(nibName: "TableCell", bundle: nil), forCellReuseIdentifier: "cell")

OR

tableView.register(TableCell.self, forCellReuseIdentifier: "cell")

It's clear here from the crash

unable to dequeue a cell with identifier cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

like image 108
Sh_Khan Avatar answered Oct 26 '25 06:10

Sh_Khan


As @Sh_Khan pointed out. You can register the cell in code or you can also register the reuse identifier in Storyboard, if you are using prototype cells.

enter image description here

like image 36
azamsharp Avatar answered Oct 26 '25 05:10

azamsharp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!