Study/Swift
[swift error] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier reuseIdentifier
minulbora
2024. 12. 27. 15:47
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier reuseIdentifier - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
*** First throw call stack:
(
0 CoreFoundation 0x00000001804b70ec __exceptionPreprocess + 172
1 libobjc.A.dylib 0x000000018008ede8 objc_exception_throw + 72
2 Foundation 0x0000000180e73aa8 _userInfoForFileAndLine + 0
3 UIKitCore 0x0000000185ce1d94 -[UITableView _dequeueReusableCellWithIdentifier:forIndexPath:usingPresentationValues:] + 748
4 UIKitCore 0x0000000185ce1a84 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 68
5 Table.debug.dylib 0x0000000103691918 $s5Table0A14ViewControllerC05tableB0_12cellForRowAtSo07UITableB4CellCSo0iB0C_10Foundation9IndexPathVtF + 264
6 Table.debug.dylib 0x0000000103691d8c $s5Table0A14ViewControllerC05tableB0_12cellForRowAtSo07UITableB4CellCSo0iB0C_10Foundation9IndexPathVtFTo + 136
7 UIKitCore 0x0000000185cf6c6c -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 1380
8 UIKitCore 0x0000000185cc93e0 -[UITableView _updateVisibleCellsForRanges:createIfNecessary:] + 548
9 UIKitCore 0x0000000185cc99e8 -[UITableView _updateVisibleCellsNow:] + 1108
10 UIKitCore 0x0000000185ce3d30 -[UITableView layoutSubviews] + 144
11 UIKitCore 0x000000018601c0c4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2404
12 QuartzCore 0x000000018b06ceb0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 432
13 QuartzCore 0x000000018b077c34 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 124
14 QuartzCore 0x000000018afacc58 _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 464
15 QuartzCore 0x000000018afdb468 _ZN2CA11Transaction6commitEv + 652
16 UIKitCore 0x0000000185abb7b4 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 32
17 CoreFoundation 0x000000018041b0ec __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 20
18 CoreFoundation 0x000000018041a824 __CFRunLoopDoBlocks + 352
19 CoreFoundation 0x00000001804150c8 __CFRunLoopRun + 812
20 CoreFoundation 0x0000000180414960 CFRunLoopRunSpecific + 536
21 GraphicsServices 0x0000000190183b10 GSEventRunModal + 160
22 UIKitCore 0x0000000185aa2b40 -[UIApplication _run] + 796
23 UIKitCore 0x0000000185aa6d38 UIApplicationMain + 124
24 UIKitCore 0x0000000184e9a184 block_destroy_helper.22 + 9660
25 Table.debug.dylib 0x0000000103690940 $sSo21UIApplicationDelegateP5UIKitE4mainyyFZ + 120
26 Table.debug.dylib 0x00000001036908b8 $s5Table11AppDelegateC5$mainyyFZ + 44
27 Table.debug.dylib 0x00000001036909bc __debug_main_executable_dylib_entry_point + 28
28 dyld 0x0000000102c05410 start_sim + 20
29 ??? 0x0000000102d9e154 0x0 + 4342800724
30 ??? 0xdc7a000000000000 0x0 + 15887010635502845952
)
libc++abi: terminating due to uncaught exception of type NSException
Assertion failure in -[UITableView _dequeueReusableCellWithIdentifier:forIndexPath:usingPresentationValues:], UITableView.m:10099
결론적으로는 identifier 가 잘못되었다는 뜻!
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
cell.textLabel?.text = items[(indexPath as NSIndexPath).row]
//셀의 text lable 앞에 선언한 items를 대입
cell.imageView?.image = UIImage(named: itemsImageFile[(indexPath as NSIndexPath).row])
return cell
}
여기서 주석처리로 기본 제공한 함수를 사용했는데, 그러다보니 withIdentifier 이름이 통일되지 않아 생긴 오류다.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath)
cell.textLabel?.text = items[(indexPath as NSIndexPath).row]
//셀의 text lable 앞에 선언한 items를 대입
cell.imageView?.image = UIImage(named: itemsImageFile[(indexPath as NSIndexPath).row])
return cell
}
이렇게 변경해주면 해결.