美文网首页
iOS运行报错:cell reuse indentifier i

iOS运行报错:cell reuse indentifier i

作者: 可bing | 来源:发表于2021-06-24 17:43 被阅读0次

老项目突然出现这个crash,当初开发的时候并未没报这个错,猜测应该是Xcode升级后的事儿,当然问题根源还是在代码上。

源代码:
1、用xib创建UITableViewCell:testTableViewCell.xib
2、UITableView注册cell:[tableView registerNib:[UINib nibWithNibName:@“testTableViewCell” bundle:nil] forCellReuseIdentifier:@“identifier2”];
3、复用池获取cell: UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifier2"];

报错日志:

Exception name:NSInternalInconsistencyException
Exception reason:cell reuse indentifier in nib (identifier1) does not match the identifier used to register the nib (identifier2)
Exception stack :[
    0   CoreFoundation                      0x000000018151ae14 B04B698D-3699-38CA-8A94-62CB458C8F89 + 855572,
    1   libobjc.A.dylib                     0x000000019852e0d8 objc_exception_throw + 56,
    2   Foundation                          0x0000000182c6de88 0EA4BB66-BF72-355F-A4A0-F27AA1B7CB22 + 1109640,
    3   UIKitCore                           0x000000018382c408 998657EE-5337-3100-9165-1E387EDCF5DD + 877576,
    4   UIKitCore                           0x00000001838a044c 998657EE-5337-3100-9165-1E387EDCF5DD + 1352780,
    5   TestApp                             0x0000000102c6bbf0 -[viewController tableView:cellForRowAtIndexPath:] + 272,
    6   UIKitCore                           0x000000018389e878 998657EE-5337-3100-9165-1E387EDCF5DD + 1345656,
    7   UIKitCore                           0x00000001846c3634 998657EE-5337-3100-9165-1E387EDCF5DD + 16176692,
    8   UIKitCore                           0x0000000183856998 998657EE-5337-3100-9165-1E387EDCF5DD + 1051032,
    9   UIKitCore                           0x000000018385643c 998657EE-5337-3100-9165-1E387EDCF5DD + 1049660,
    10  UIKitCore                           0x0000000183759c70 998657EE-5337-3100-9165-1E387EDCF5DD + 15472,
    11  QuartzCore                          0x0000000184ebd518 66B39605-0B88-3A9A-ACFD-76BFCFC78C4F + 17688,
    12  QuartzCore                          0x0000000184ecb02c 66B39605-0B88-3A9A-ACFD-76BFCFC78C4F + 73772,
    13  QuartzCore                          0x0000000184ef2fdc 66B39605-0B88-3A9A-ACFD-76BFCFC78C4F + 237532,
    14  QuartzCore                          0x0000000184f2c698 66B39605-0B88-3A9A-ACFD-76BFCFC78C4F + 472728,
    15  QuartzCore                          0x000000018506f42c 66B39605-0B88-3A9A-ACFD-76BFCFC78C4F + 1795116,
    16  CoreFoundation                      0x00000001814ca374 B04B698D-3699-38CA-8A94-62CB458C8F89 + 525172,
    17  CoreFoundation                      0x000000018145c2a4 B04B698D-3699-38CA-8A94-62CB458C8F89 + 74404,
    18  CoreFoundation                      0x00000001814b7f4c B04B698D-3699-38CA-8A94-62CB458C8F89 + 450380,
    19  CoreFoundation                      0x00000001814c4ddc CFRunLoopRunSpecific + 572,
    20  GraphicsServices                    0x000000019b548afc GSEventRunModal + 160,
    21  UIKitCore                           0x0000000183b06d70 998657EE-5337-3100-9165-1E387EDCF5DD + 3870064,
    22  UIKitCore                           0x0000000183b067f8 UIApplicationMain + 2140,
    23  TestApp                             0x0000000102f2f3bc main + 120,
    24  dyld                                0x0000000105ad11d0 start + 444
]
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/GPUTools.framework/libglInterpose.dylib:/usr/lib/libMTLCapture.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'cell reuse indentifier in nib (identifier1) does not match the identifier used to register the nib (identifier2)’
terminating with uncaught exception of type NSException

报错原因:

- (void)registerNib:(nullable UINib *)nib forCellReuseIdentifier:(NSString *)identifier;
- (nullable __kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier;

说是上面两个方法中的identifier值不一致。

可是源代码里面的identifier值明明是一样的identifier2,那这identifier1哪儿冒出来的,猜想应该是自己在某个地方手动写入的,最后顺着这个值找到原来是xib文件里面的配置出了问题:

罪魁祸首
清空这个identifier属性值就OK了!

只能以两个不同identifier冲突来解释了。

相关文章

网友评论

      本文标题:iOS运行报错:cell reuse indentifier i

      本文链接:https://www.haomeiwen.com/subject/pkcgyltx.html