应用程序在 iOS 10 岁及以上时因 "Could not instantiate class named _UIScrollViewLayoutGuide" 而崩溃

App crashes with "Could not instantiate class named _UIScrollViewLayoutGuide" on iOS 10 and older

我遇到了以下错误,none 现有的 Stack Overflow 答案对我有所帮助。我很难通过查看控制台结果找到错误形成的确切位置。

这是我在旧设备上 运行 时遇到的错误(在新设备上工作正常)。我可以尝试哪些事情来确定问题?

2019-12-30 16:52:04.784 Hospital[7075:164758] *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named _UIScrollViewLayoutGuide'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010ad9fb0b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010a804141 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010ae08625 +[NSException raise:format:] + 197

    3   UIKit                               0x000000010c15368d UINibDecoderDecodeObjectForValue + 323

    4   UIKit                               0x000000010c15353f -[UINibDecoder decodeObjectForKey:] + 89
    5   Foundation                          0x0000000109b0e417 -[NSLayoutConstraint initWithCoder:] + 757
    6   UIKit                               0x000000010c1537ff UINibDecoderDecodeObjectForValue + 693

    7   UIKit                               0x000000010c15399d UINibDecoderDecodeObjectForValue + 1107

    8   UIKit                               0x000000010c15353f -[UINibDecoder decodeObjectForKey:] + 89
    9   UIKit                               0x000000010bbee9de -[UIView initWithCoder:] + 2209
    10  UIKit                               0x000000010bc29687 -[UIScrollView initWithCoder:] + 71
    11  UIKit                               0x000000010c1537ff UINibDecoderDecodeObjectForValue + 693
    12  UIKit                               0x000000010c15399d UINibDecoderDecodeObjectForValue + 1107
    13  UIKit                               0x000000010c15353f -[UINibDecoder decodeObjectForKey:] + 89
    14  UIKit                               0x000000010bbee4ed -[UIView initWithCoder:] + 944
    15  UIKit                               0x000000010c1537ff UINibDecoderDecodeObjectForValue + 693

    16  UIKit                               0x000000010c15353f -[UINibDecoder decodeObjectForKey:] + 89
    17  UIKit                               0x000000010bf62f70 -[UIRuntimeConnection initWithCoder:] + 178
    18  UIKit                               0x000000010c1537ff UINibDecoderDecodeObjectForValue + 693
    19  UIKit                               0x000000010c15399d UINibDecoderDecodeObjectForValue + 1107
    20  UIKit                               0x000000010c15353f -[UINibDecoder a:] + 89
    21  UIKit                               0x000000010bf6216d -[UINib instantiateWithOwner:options:] + 1262
    22  UIKit                               0x000000010bcfcfc3 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
    23  UIKit                               0x000000010bcfd8d9 -[UIViewController loadView] + 177
    24  UIKit                               0x000000010bcfdc0a -[UIViewController loadViewIfRequired] + 195
    25  UIKit                               0x000000010bcfe45a -[UIViewController view] + 27
    26  Hospital                     0x00000001086ecb00 $s15_Hospital15PagerScrollViewC03setcdE010toParentVC05pagesI0ySo16UIViewControllerC_SayAHGSgtF + 1152
    27  Hospital                     0x00000001086f6b85 $s15_Hospital22HomeMainViewControllerC11viewDidLoadyyF + 3861
    28   Hospital                     0x00000001086f6e9b $s15_Hospital22HomeMainViewControllerC11viewDidLoadyyFTo + 43
    29  UIKit                               0x000000010bcfe01a -[UIViewController loadViewIfRequired] + 1235
    30  UIKit                               0x000000010bd3ce6c -[UINavigationController _layoutViewController:] + 56
    31  UIKit                               0x000000010bd3d74a -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 466
    32  UIKit                               0x000000010bd3d8bb -[UINavigationController _startTransition:fromViewController:toViewController:] + 127
    33  UIKit                               0x000000010bd3ea03 -[UINavigationController _startDeferredTransitionIfNeeded:] + 843
    34  UIKit                               0x000000010bd3fb41 -[UINavigationController __viewWillLayoutSubviews] + 58
    35  UIKit                               0x000000010bf3160c -[UILayoutContainerView layoutSubviews] + 231
    36  UIKit                               0x000000010bc1e55b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1268
    37  QuartzCore                          0x000000010a572904 -[CALayer layoutSublayers] + 146
    38  QuartzCore                          0x000000010a566526 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 370
    39  QuartzCore                          0x000000010a5663a0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    40  QuartzCore                          0x000000010a4f5e92 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    41  QuartzCore                          0x000000010a522130 _ZN2CA11Transaction6commitEv + 468
    42  QuartzCore                          0x000000010a522b37 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 115
    43  CoreFoundation                      0x000000010ad45717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23

    44  CoreFoundation                      0x000000010ad45687 __CFRunLoopDoObservers + 391
    45  CoreFoundation                      0x000000010ad2a038 CFRunLoopRunSpecific + 440
    46  UIKit                               0x000000010bb5508f -[UIApplication _run] + 468
    47  UIKit                               0x000000010bb5b134 UIApplicationMain + 159
    48   Hospital                     0x000000010872773b main + 75
    49  libdyld.dylib                       0x000000010e5d965d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

请检查源代码中的以下内容:

  1. 检查您的 Xib 或 Storyboard 文件是否有关于 IBOutlet 或 IBAction 连接。
  2. 看起来错误应该在您的 Xib 或 Storyboard 中,因为错误日志回溯显示 UINibDecoder 错误。
  3. UILayoutGuide 可从 iOS 9.0+ 开始使用,因此请检查您应用的部署目标,它应该是 iOS 9 或更高版本。
  4. 您还提到您只在较旧的设备中看到此问题,这些设备可能 运行 小于 iOS 9.
  5. 在 Xcode 的文件检查器中取消选中 "Use Safe Area Layout Guides" 选项。
  6. 最后检查您以前的源代码工作版本,并将最近的更改与错误代码库进行比较,以确定崩溃的原因。

我有同样的问题(使用 Xcode11 和 运行 iOS 10.3.1)。 从滚动视图中取消选中内容布局指南对我有用。

image

感谢@Luke 的回答,我找到了问题的确切原因:它是由任何项目和滚动视图的内容布局指南之间的约束引起的。

所以要找到问题所在:

  1. 检查日志找出哪个视图控制器参与了问题。根据@Jaseel.Dev显示的日志是"Alexis_Hospital"
  2. 在 Interface Builder 的视图控制器中检查所有滚动视图及其内容布局指南或框架布局指南
  3. 有 2 种修复方法:

a) 单击滚动视图,取消选中 [ ] Content Layout Guides 并再次选中它们(Interface Builder 会将 "layout guide" 边重新分配给 "superview")

b) 点击 Content Autolayout Guide 并检查是否有任何约束指向它们。摆脱这些限制。

主要想法是删除这些限制,这些限制会在 iOS 10 及更早版本上崩溃。