0
votes

I am using Xib file as a custom Tableview Cell. But everytime i run my application, it crashes. I get this crash logs which i posted below

* Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.7.47/UITableView.m:6730 2017-12-04 17:23:16.070 iCommander[2489:135476] * 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 0x00000001035f6b0b exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010305b141 objc_exception_throw + 48 2 CoreFoundation 0x00000001035facf2 +[NSException raise:format:arguments:] + 98 3 Foundation 0x0000000102bf5536 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193 4 UIKit 0x00000001042eae45 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 241 5 iCommander 0x0000000101e6b43f _TFC10iCommander25CommentsHistoryController9tableViewfTCSo11UITableView12cellForRowAtV10Foundation9IndexPath_CSo15UITableViewCell + 303 6 iCommander 0x0000000101e6ba07 _TToFC10iCommander25CommentsHistoryController9tableViewfTCSo11UITableView12cellForRowAtV10Foundation9IndexPath_CSo15UITableViewCell + 87 7 UIKit 0x00000001042fdab2 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 750 8 UIKit 0x00000001042fdcf8 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74 9 UIKit 0x00000001042d2639 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2845 10 UIKit 0x0000000104306ccc -[UITableView _performWithCachedTraitCollection:] + 111 11 UIKit 0x00000001042ede7a -[UITableView layoutSubviews] + 233 12 UIKit 0x000000010425455b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1268 13 QuartzCore 0x0000000102429904 -[CALayer layoutSublayers] + 146 14 QuartzCore 0x000000010241d526 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 370 15 QuartzCore 0x000000010241d3a0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 16 QuartzCore 0x00000001023ace92 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294 17 QuartzCore 0x00000001023d9130 _ZN2CA11Transaction6commitEv + 468 18 QuartzCore 0x00000001023d9b37 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 115 19 CoreFoundation 0x000000010359c717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23 20 CoreFoundation 0x000000010359c687 __CFRunLoopDoObservers + 391 21 CoreFoundation 0x0000000103581720 __CFRunLoopRun + 1200 22 CoreFoundation 0x0000000103581016 CFRunLoopRunSpecific + 406 23 GraphicsServices 0x00000001091e1a24 GSEventRunModal + 62 24 UIKit 0x0000000104191134 UIApplicationMain + 159 25 iCommander 0x0000000101e13ea7 main + 55 26 libdyld.dylib 0x000000010743e65d start + 1 27 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException

Please help. Thanks in advance.

3
Did you read the crash log? 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'dasdom
got it. Thanks for the help. Problem solved.NoobDev

3 Answers

5
votes

You forgot to register the XIB file. You have to register the xib file for getting rid of the crash.

In Swift 3

 let xib = UINib(nibName: "YourCustomCell", bundle: nil)
 tableView.register(xib, forCellReuseIdentifier: "Cell")

You should register the custom cell like that.

Hope it helps.

0
votes

Set cell identifier to custom cell in xib file as:setting cell identifier for reusing cell with that identifier

0
votes

IN Swift 3

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
    {
        let cell = Bundle.main.loadNibNamed("XibName", owner: self, options: nil)?.first as! XibName

 return cell

    }