【问题标题】:Adding a container causes NSInternalInconsistencyException添加容器会导致 NSInternalInconsistencyException
【发布时间】:2019-05-19 08:49:07
【问题描述】:

我正在尝试向我的应用添加容器视图。但是,它不断崩溃并出现以下错误:

'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工作区的图片:

【问题讨论】:

    标签: ios swift xcode uiview uicontainerview


    【解决方案1】:

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

    • 您的 ViewController 是一个带有单个子视图控制器的父视图控制器,通过嵌入 segue 的方式在此处设置;它在“容器视图”的范围内显示子视图控制器的视图。

    • UIPageViewController也是一个父视图控制器,它有一个子视图控制器,它将显示为它的页面;它在自己的视图的整个边界中显示子视图控制器的视图。

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

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

    但是,还请注意,您可以使用页面视图控制器作为原始视图控制器的子视图控制器。这是完全合法且非常普遍的!事实上,能够做到这一点是必不可少的,因为否则页面视图控制器将始终是全屏的,这可能不是您想要的。

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

    那个就是你要改成UIPageViewController的视图控制器,这样做是合法的。删除这个视图控制器,将一个 UIPageViewController 拖到故事板中,然后将一个新的 Embed Segue 从容器视图拖到 UIPageViewController。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-14
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      • 2015-04-17
      • 2013-07-14
      相关资源
      最近更新 更多