NSGenericException:此编码器要求从 initWithCoder 返回替换的对象

NSGenericException: This coder requires that replaced objects be returned from initWithCoder

我昨天 运行 我的 iPhone 应用程序还不错。今天我遇到了这个崩溃:

*** Terminating app due to uncaught exception 'NSGenericException', reason: 'This coder requires that replaced objects be returned from initWithCoder:'

当使用故事板 segue 从一个视图转到另一个视图时会发生这种情况(也以编程方式尝试过)。目标视图控制器是一个 UITableViewController,没有什么奇怪的。我回滚了我的代码以检查是否有任何更改导致此崩溃但没有。我制作的最新测试版本仍然可以使用相同的代码正常工作。

有人知道哪里出了问题吗?我没主意了。

这是堆栈跟踪:

0   CoreFoundation                      0x0000000107f176fb __exceptionPreprocess + 331
1   libobjc.A.dylib                     0x0000000106f0bac5 objc_exception_throw + 48
2   CoreFoundation                      0x0000000107f17555 +[NSException raise:format:] + 197
3   UIFoundation                        0x000000010d3fe89c UINibDecoderDecodeObjectForValue + 827
4   UIFoundation                        0x000000010d3feaf9 UINibDecoderDecodeObjectForValue + 1432
5   UIFoundation                        0x000000010d3fe554 -[UINibDecoder decodeObjectForKey:] + 251
6   UIKitCore                           0x000000010f4b0330 -[UIViewController initWithCoder:] + 1021
7   UIKitCore                           0x000000010f4a52ab -[UITableViewController initWithCoder:] + 59
8   Tankey                              0x0000000100c8ede4 $s6Tankey25BaseUITableViewControllerC5coderACSgSo7NSCoderC_tcfc + 148
9   Tankey                              0x0000000100c8ee8f $s6Tankey25BaseUITableViewControllerC5coderACSgSo7NSCoderC_tcfcTo + 47
10  Tankey                              0x0000000100bcd3fc $s6Tankey19ShareViewControllerC5coderACSgSo7NSCoderC_tcfc + 1260
11  Tankey                              0x0000000100bcd4bf $s6Tankey19ShareViewControllerC5coderACSgSo7NSCoderC_tcfcTo + 47
12  UIKitCore                           0x000000010f7354f9 -[UIClassSwapper initWithCoder:] + 246
13  UIFoundation                        0x000000010d3fe852 UINibDecoderDecodeObjectForValue + 753
14  UIFoundation                        0x000000010d3fe554 -[UINibDecoder decodeObjectForKey:] + 251
15  UIKitCore                           0x000000010f739b41 -[UIRuntimeConnection initWithCoder:] + 178
16  UIKitCore                           0x000000010f739ee2 -[UIRuntimeEventConnection initWithCoder:] + 59
17  UIFoundation                        0x000000010d3fe852 UINibDecoderDecodeObjectForValue + 753
18  UIFoundation                        0x000000010d3feaf9 UINibDecoderDecodeObjectForValue + 1432
19  UIFoundation                        0x000000010d3fe554 -[UINibDecoder decodeObjectForKey:] + 251
20  UIKitCore                           0x000000010f7373f1 -[UINib instantiateWithOwner:options:] + 1216
21  UIKitCore                           0x000000010fc4fc60 -[UIStoryboard instantiateViewControllerWithIdentifier:] + 181
22  UIKitCore                           0x000000010fc507fb -[UIStoryboardSegueTemplate instantiateOrFindDestinationViewControllerWithSender:] + 90
23  UIKitCore                           0x000000010fc50a3f -[UIStoryboardSegueTemplate _perform:] + 52
24  UIKitCore                           0x000000010f4b854b -[UIViewController performSegueWithIdentifier:sender:] + 99
25  UIKit                               0x0000000127bdeec1 -[UIViewControllerAccessibility performSegueWithIdentifier:sender:] + 102
26  Tankey                              0x0000000100affb30 $s6Tankey22SettingsViewControllerC05tableC0_14didSelectRowAtySo07UITableC0C_10Foundation9IndexPathVtF + 1280
27  Tankey                              0x0000000100b0047e $s6Tankey22SettingsViewControllerC05tableC0_14didSelectRowAtySo07UITableC0C_10Foundation9IndexPathVtFTo + 158
28  UIKitCore                           0x000000010fcd2419 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1810
29  UIKitCore                           0x000000010fcd262d -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 337
30  UIKitCore                           0x000000010fac2cc9 _runAfterCACommitDeferredBlocks + 318
31  UIKitCore                           0x000000010fab2199 _cleanUpAfterCAFlushAndRunDeferredBlocks + 358
32  UIKitCore                           0x000000010fadf32b _afterCACommitHandler + 124
33  CoreFoundation                      0x0000000107e7e0f7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
34  CoreFoundation                      0x0000000107e785be __CFRunLoopDoObservers + 430
35  CoreFoundation                      0x0000000107e78c31 __CFRunLoopRun + 1505
36  CoreFoundation                      0x0000000107e78302 CFRunLoopRunSpecific + 626
37  GraphicsServices                    0x000000010d0a22fe GSEventRunModal + 65
38  UIKitCore                           0x000000010fab7ba2 UIApplicationMain + 140
39  Tankey                              0x0000000100aee518 main + 72
40  libdyld.dylib                       0x000000010958f541 start + 1
41  ???                                 0x0000000000000001 0x0 + 1

我注意到 Xcode 在正常运行的应用程序和崩溃的应用程序之间进行了更新。我从 Xcode 10.2 回滚到 10.1,现在崩溃消失了,应用程序运行正常。

回滚是一种解决方法,而不是解决方法。

问题出在我使用的 pod(称为 Inputmask)中,同​​时问题已在 pod 中修复,现在使用 Xcode 10.2 一切正常。

感谢 Tom Spee 为我节省了这么多时间。

我遇到了完全相同的问题。我只是使用 carthage 而不是 cocoapods。

该问题存在于 InputMask 库版本 4.1.0 中,该问题已在其版本 4.1.1 中修复

有关修复崩溃的提交的更多信息,这里是 link: https://github.com/RedMadRobot/input-mask-ios/commit/c2f0d9bcc49567a6c0bcc4173dd410a969fcc423

在大多数情况下,真正的解决方法如下。记住不要 return nil 在下面的初始值设定项中:

required init?(coder: NSCoder) {
    super.init(coder: coder)
}