由于名称为“OverlayView”的未捕获异常“NSInternalInconsistencyException”而终止应用程序

Posted

技术标签:

【中文标题】由于名称为“OverlayView”的未捕获异常“NSInternalInconsistencyException”而终止应用程序【英文标题】:Terminating app due to uncaught exception 'NSInternalInconsistencyException' with name 'OverlayView' 【发布时间】:2016-08-20 09:23:51 【问题描述】:

我打算通过Podfile 在我新创建的 swift xcode 项目中使用自定义视图Koloda。在pod install之后,在Main.storyboard中创建KolodaView并构建成功,运行时报异常如下:

2016-08-20 09:44:38.918 MsgNotFree[25760:2220650] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/jasonzhu/Library/Developer/CoreSimulator/Devices/DDE42B9D-6304-4552-AD30-A1BFA3A7B3E0/data/Containers/Bundle/Application/D1282CEB-9914-4C37-BCD2-DC05675C9FD1/MsgNotFree.app> (loaded)' with name 'OverlayView''
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010a227d85 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010c8d4deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010a227cbd +[NSException raise:format:] + 205
    3   UIKit                               0x000000010b720c89 -[UINib instantiateWithOwner:options:] + 499
    4   UIKit                               0x000000010b723415 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 223
    5   MsgNotFree                          0x0000000109eedd90 _TFC10MsgNotFree19FirstViewController6kolodafTCS_10KolodaView25viewForCardOverlayAtIndexSu_GSqCS_11OverlayView_ + 368
    6   MsgNotFree                          0x0000000109eedf92 _TToFC10MsgNotFree19FirstViewController6kolodafTCS_10KolodaView25viewForCardOverlayAtIndexSu_GSqCS_11OverlayView_ + 66
    7   MsgNotFree                          0x0000000109eee918 _TTDFC10MsgNotFree19FirstViewController6kolodafTCS_10KolodaView25viewForCardOverlayAtIndexSu_GSqCS_11OverlayView_ + 56
    8   MsgNotFree                          0x0000000109eee085 _TTWC10MsgNotFree19FirstViewControllerS_20KolodaViewDataSourceS_FS1_6kolodafTCS_10KolodaView25viewForCardOverlayAtIndexSu_GSqCS_11OverlayView_ + 53
    9   Koloda                              0x0000000109ff14f5 _TFC6Koloda10KolodaView13configureCardfTCS_17DraggableCardView7atIndexSu_T_ + 501
    10  Koloda                              0x0000000109ff15b2 _TToFC6Koloda10KolodaView13configureCardfTCS_17DraggableCardView7atIndexSu_T_ + 66
    11  Koloda                              0x0000000109ff1183 _TFC6Koloda10KolodaView17createCardAtIndexfTSu5frameGSqVSC6CGRect__CS_17DraggableCardView + 611
    12  Koloda                              0x0000000109ff292b _TFC6Koloda10KolodaViewP33_DFF55D12D516409CF60937DD60F8B8969setupDeckfT_T_ + 955
    13  Koloda                              0x0000000109ff1e60 _TFC6Koloda10KolodaViewW10dataSourceXwGSqPS_20KolodaViewDataSource__ + 32
    14  Koloda                              0x0000000109ff1f60 _TFC6Koloda10KolodaViews10dataSourceXwGSqPS_20KolodaViewDataSource__ + 160
    15  MsgNotFree                          0x0000000109eec73e _TFC10MsgNotFree19FirstViewController11viewDidLoadfT_T_ + 398
    16  MsgNotFree                          0x0000000109eec802 _TToFC10MsgNotFree19FirstViewController11viewDidLoadfT_T_ + 34
    17  UIKit                               0x000000010b4f3984 -[UIViewController loadViewIfRequired] + 1198
    18  UIKit                               0x000000010b4f3cd3 -[UIViewController view] + 27
    19  UIKit                               0x000000010b5571bc -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 502
    20  UIKit                               0x000000010b556130 -[UITabBarController transitionFromViewController:toViewController:] + 59
    21  UIKit                               0x000000010b551f41 -[UITabBarController _setSelectedViewController:] + 377
    22  UIKit                               0x000000010b551db7 -[UITabBarController setSelectedViewController:] + 234
    23  UIKit                               0x000000010b408680 +[UIView(Animation) performWithoutAnimation:] + 65
    24  UIKit                               0x000000010b54bddc -[UITabBarController _selectDefaultViewControllerIfNecessaryWithAppearanceTransitions:] + 344
    25  UIKit                               0x000000010b54d5df -[UITabBarController viewWillAppear:] + 193
    26  UIKit                               0x000000010b4f92bd -[UIViewController _setViewAppearState:isAnimating:] + 710
    27  UIKit                               0x000000010b4f9958 -[UIViewController __viewWillAppear:] + 149
    28  UIKit                               0x000000010b401255 -[UIView(Hierarchy) _willMoveToWindow:withAncestorView:] + 633
    29  UIKit                               0x000000010b40fc9e -[UIView(Internal) _addSubview:positioned:relativeTo:] + 481
    30  UIKit                               0x000000010b3ca29a -[UIWindow addRootViewControllerViewIfPossible] + 803
    31  UIKit                               0x000000010b3ca69d -[UIWindow _setHidden:forced:] + 282
    32  UIKit                               0x000000010b3dc180 -[UIWindow makeKeyAndVisible] + 42
    33  UIKit                               0x000000010b350ed9 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
    34  UIKit                               0x000000010b357568 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1769
    35  UIKit                               0x000000010b354714 -[UIApplication workspaceDidEndTransaction:] + 188
    36  FrontBoardServices                  0x000000010d40f8c8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
    37  FrontBoardServices                  0x000000010d40f741 -[FBSSerialQueue _performNext] + 178
    38  FrontBoardServices                  0x000000010d40faca -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    39  CoreFoundation                      0x000000010a14d301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    40  CoreFoundation                      0x000000010a14322c __CFRunLoopDoSources0 + 556
    41  CoreFoundation                      0x000000010a1426e3 __CFRunLoopRun + 867
    42  CoreFoundation                      0x000000010a1420f8 CFRunLoopRunSpecific + 488
    43  UIKit                               0x000000010b353f21 -[UIApplication _run] + 402
    44  UIKit                               0x000000010b358f09 UIApplicationMain + 171
    45  MsgNotFree                          0x0000000109eec272 main + 114
    46  libdyld.dylib                       0x00000001112d892d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

其中,OverlayView类可以在ViewController中被引用,这意味着第三方类在项目级别被正确引用。

演示项目是here

谁能给我一些提示,问题可能出在哪里?非常感谢!

【问题讨论】:

【参考方案1】:

此错误是由于您的包中没有名为 .xib 的 overlayView 文件, 创建一个新文件 -> UserInterface -> View -> (重命名为 OverlayView) 现在得到了 OverlayView 并在那里选择视图将其类更改为 OverlayView。

【讨论】:

有效!谢谢老哥~不过我打算再进一步,为什么申请pod install时创建xib文件没有帮助?以及 xib 文件在这里真正做了什么。因为我在那里只看到一个空白视图。 因为错误说'无法在捆绑中加载NIB:'NSBundle yourpath which the your .xib is missing 我想你可能在某个地方使用过NSBundle.mainBundle().loadNibNamed并且找不到nib所以它通过一个异常

以上是关于由于名称为“OverlayView”的未捕获异常“NSInternalInconsistencyException”而终止应用程序的主要内容,如果未能解决你的问题,请参考以下文章

由于使用 AWS iOS 开发工具包的未捕获异常“NSInvalidArgumentException”而终止应用程序

自己定义Application的未捕获异常处理

Swift:以 NSException 类型的未捕获异常终止

Swift 项目以 NSException 类型的未捕获异常终止

使用 CLLocationCoordinate2D 初始化获取 NSException 类型的未捕获异常

致命错误:带有消息的未捕获异常“com_exception”。在将ppt转换为jpg时