Terminating app due to uncaught exception 'NSUnknownKeyException', reason: xxxx

出现错误的情景:

使用Swift自定义Cell, 然后将这个Cell在OC中使用, 由于为了能够在OC中使用和使用起来命名比较规范

我在Swift自定义的Cell前加了 @objc(DSProductCell)

完整版是这样的:

@objc(DSProductCell) class ProductCell: UITableViewCell {}

然后在xib上对cell进行搭建...

之后在OC使用的时候就出现了这个错误...

最后排查出现这个问题的原因:

xib中的class没有加上前缀, 也就是默认是ProductCell, 需要改为:DSProductCell

之后编译还是不行, clean了一下, 在进行编译, 就可以了...

所以在这里使用的时候需要注意一下..

另外还有一个需要注意的地方, 就是tableView在registerNib的时候, nibName是xib文件的名字,

注意, 是xib的文件名, 例如ProductCell.xib, register的时候就是:

[self.tableView registerNib:[UINib nibWithNibName:@"ProductCell" bundle:nil] forCellReuseIdentifier:reuseIdentifier];

原文地址:https://www.cnblogs.com/Rinpe/p/5530731.html