iOS运行报错:cell reuse indentifier in nib (identifier1) does not match the identifier used to registe...

老项目突然出现这个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的时候,iOS编程是我的启蒙书,那时候看觉得很有难度,现在粗略重温一遍。温故而知新,发现里面还是有...
    武当霍元甲阅读 2,823评论 0 0
  • 1,Search Bar 怎样去掉背景的颜色(storyboard里只能设置background颜色,可是发现cl...
    以德扶人阅读 7,539评论 2 50
  • UITableView UITableView内置了两种样式:UITableViewStylePlain,UITa...
    _凌浩雨阅读 4,223评论 0 1
  • 文章出处: http://www.cocoachina.com/industry/20140604/8668.ht...
    whiteking阅读 4,821评论 0 1
  • 我是黑夜里大雨纷飞的人啊 1 “又到一年六月,有人笑有人哭,有人欢乐有人忧愁,有人惊喜有人失落,有的觉得收获满满有...
    陌忘宇阅读 12,729评论 28 53