添加容器会导致NSInternalInconsistencyException

时间:2018-12-18 21:35:31

标签: ios swift xcode uiview uicontainerview

我正在尝试将容器视图添加到我的应用中。但是,它始终崩溃并显示以下错误:

“ NSInternalInconsistencyException”,原因:“ containerView是必需的。”

我制作了一个新项目来测试何时发生错误。当我添加容器视图并将其分配给类“ viewController”时,它可以正常工作(链接的图片显示了这一点)。然后,我添加一个名为“ MainViewController”的新UIPagecontroller类,并将其分配给容器所在的原始viewController-当我运行它时,它崩溃并出现相同的错误-为什么会这样?

我还没有添加任何代码,因此我没有要链接的内容,但这是控制台错误:

2018-12-18 21:25:38.171283+0000 caca2[19001:1863302] *** Assertion failure in -[UIStoryboardEmbedSegueTemplate newDefaultPerformHandlerForSegue:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3698.54.4/UIStoryboardEmbedSegueTemplate.m:34
2018-12-18 21:25:38.190027+0000 caca2[19001:1863302] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'containerView is required.'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000107b921e6 __exceptionPreprocess + 294
    1   libobjc.A.dylib                     0x0000000103ff8031 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000107b97472 +[NSException raise:format:arguments:] + 98
    3   Foundation                          0x0000000103a9b652 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
    4   UIKit                               0x00000001054cb49e __67-[UIStoryboardEmbedSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 796
    5   UIKit                               0x00000001051b8f47 -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 276
    6   UIKit                               0x00000001051b8e05 -[UIStoryboardSegueTemplate _perform:] + 82
    7   UIKit                               0x00000001051b90c7 -[UIStoryboardSegueTemplate perform:] + 157
    8   UIKit                               0x0000000104a37f11 -[UIViewController loadViewIfRequired] + 671
    9   UIKit                               0x0000000104a38574 -[UIViewController view] + 27
    10  UIKit                               0x0000000104906123 -[UIWindow addRootViewControllerViewIfPossible] + 122
    11  UIKit                               0x0000000104906834 -[UIWindow _setHidden:forced:] + 294
    12  UIKit                               0x00000001049195cc -[UIWindow makeKeyAndVisible] + 42
    13  UIKit                               0x000000010488d3da -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4739
    14  UIKit                               0x00000001048925cb -[UIApplication _runWithMainScene:transitionContext:completion:] + 1677
    15  UIKit                               0x0000000104c54f7e __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 866
    16  UIKit                               0x0000000105027a39 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
    17  UIKit                               0x0000000104c54bba -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 236
    18  UIKit                               0x0000000104c553db -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 675
    19  UIKit                               0x00000001055c6614 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 299
    20  UIKit                               0x00000001055c64ae -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 433
    21  UIKit                               0x00000001052aa75d __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 221
    22  UIKit                               0x00000001054a54b7 _performActionsWithDelayForTransitionContext + 100
    23  UIKit                               0x00000001052aa627 -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 223
    24  UIKit                               0x00000001050270e0 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
    25  UIKit                               0x0000000104890eac -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 515
    26  UIKit                               0x0000000104e63bcb -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361
    27  FrontBoardServices                  0x0000000109bc22f3 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 331
    28  FrontBoardServices                  0x0000000109bcacfa __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 225
    29  libdispatch.dylib                   0x0000000108cf67ec _dispatch_client_callout + 8
    30  libdispatch.dylib                   0x0000000108cfbdb8 _dispatch_block_invoke_direct + 592
    31  FrontBoardServices                  0x0000000109bf6470 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
    32  FrontBoardServices                  0x0000000109bf612e -[FBSSerialQueue _performNext] + 439
    33  FrontBoardServices                  0x0000000109bf668e -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    34  CoreFoundation                      0x0000000107b34bb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    35  CoreFoundation                      0x0000000107b194af __CFRunLoopDoSources0 + 271
    36  CoreFoundation                      0x0000000107b18a6f __CFRunLoopRun + 1263
    37  CoreFoundation                      0x0000000107b1830b CFRunLoopRunSpecific + 635
    38  GraphicsServices                    0x000000010a48ba73 GSEventRunModal + 62
    39  UIKit                               0x0000000104894057 UIApplicationMain + 159
    40  caca2                               0x00000001036edd37 main + 55
    41  libdyld.dylib                       0x0000000108d73955 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

对于如何解决此问题的任何帮助或建议,将不胜感激! 谢谢

模拟器和xcode工作区的图像:

enter image description here

1 个答案:

答案 0 :(得分:0)

简而言之,这是因为您正在做的事情毫无意义。

  • 您的ViewController是具有单个子视图控制器的父视图控制器,此处通过embed segue进行设置;它在“容器视图”的边界内显示子视图控制器的视图。

  • UIPageViewController也是 一个具有单个子视图控制器的父视图控制器,它将显示为其页面;它将在其自身视图的整个范围内显示子视图控制器的视图。

这些是完全不同的视图父视图控制器,用于管理其子级并以完全不同的方式显示其视图。您必须选择一个或另一个;视图控制器不能同时是两种父级。但这就是您想要实现的目标。

因此,如果要使用自定义父视图控制器(第一个选项),则应从情节提要中显示的排列开始,然后停止。如果要使用页面视图控制器,则需要删除显示的所有内容,并使用页面视图控制器开始

但是,还请注意,您可以将页面视图控制器用作原始视图控制器的子视图控制器。那是完全合法的,而且很普遍!实际上,做到这一点至关重要,因为否则页面视图控制器将始终是全屏的,而这可能并不是您想要的。

为此,请不要将ViewController更改为UIPageViewController。将情节提要(子级)中的 other 视图控制器更改为UIPageViewController。

enter image description here

那个是要更改为UIPageViewController的视图控制器,这样做是合法的。删除此视图控制器,将UIPageViewController拖到情节提要中,然后将新的Embed Segue从容器视图拖到UIPageViewController。

enter image description here