4

我在我的 iOS 应用程序中实现了一个下拉菜单,它调用函数在不同的故事板之间导航。该菜单中的每个元素都使用不同的故事板名称调用 AppDelegate 类中的以下函数:

(void)changeController:(NSString*)storyboardName
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:[NSBundle mainBundle]];

    //initialize the new view
    currentView = [storyboard instantiateInitialViewController];
    currentView.view.alpha = 0.0;
    currentView.view.frame = currentView.view.bounds;
    currentView.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    //the app crashes on this line with a Thread 1: signal SIGARBT message
    self.window.rootViewController = currentView;
    [self.window makeKeyAndVisible];

    //animate with a fade transition
    [UIView animateWithDuration:transitionDuration
                          delay:0.0
                        options:UIViewAnimationOptionCurveLinear
                     animations:^{currentView.view.alpha = 1.0;}
                     completion:^(BOOL finished){}];
}

问题是被调用的函数不一致地使应用程序崩溃。它适用于某些屏幕,而不适用于其他屏幕。更糟糕的是,它有时可以在通常崩溃的屏幕上运行。

有两条错误消息被转储到控制台,它们是(为了便于阅读,我添加了换行符):

Objective: {
 objective 0x15e4b3c0: <750:-1.64135e-05> + <750:8.34465e-08>
 *<orphaned without delegate (bug!):0x1703c790>{id: 188} + <750:4.17233e-08>
 *<orphaned without delegate (bug!):0x1703c980>{id: 192} + <750:-2.68221e-08>
 *UIView:0x170c6e40.Height{id: 1091}
}

uncaught exception: <NSISEngine: 0x15e0b380>{ Rows:
    UIWindow:0x15db3160.Height{id: 140} == 960 + 1*0x15dd03e0.marker{id: 144}
    UIWindow:0x15db3160.Width{id: 137} == 640 + 1*0x15dd03b0.marker{id: 141}
    UIWindow:0x15db3160.minX{id: 136} == 0 + 2*0x15dd0200.marker{id: 135} + -0.5*0x15dd03b0.marker{id: 141}
    UIWindow:0x15db3160.minY{id: 139} == 0 + 2*0x15dd0350.marker{id: 138} + -0.5*0x15dd03e0.marker{id: 144}
    objective{id: 1} == {
         objective 0x15e4b3c0: <750:-1.64135e-05> + <750:8.34465e-08>
         *<orphaned without delegate (bug!):0x1703c790>{id: 188} + <750:4.17233e-08>
         *<orphaned without delegate (bug!):0x1703c980>{id: 192} + <750:-2.68221e-08>
         *UIView:0x170c6e40.Height{id: 1091}}

     Constraints:
         <NSAutoresizingMaskLayoutConstraint:0x15dd03b0 h=--- v=--- H:[UIWindow:0x15db3160(320)]>       Marker:0x15dd03b0.marker{id: 141}
         <NSAutoresizingMaskLayoutConstraint:0x15dd03e0 h=--- v=--- V:[UIWindow:0x15db3160(480)]>       Marker:0x15dd03e0.marker{id: 144}
         <_UIWindowAnchoringConstraint:0x15dd0200 h=--- v=--- UIWindow:0x15db3160.midX == + 160>        Marker:0x15dd0200.marker{id: 135}
         <_UIWindowAnchoringConstraint:0x15dd0350 h=--- v=--- UIWindow:0x15db3160.midY == + 240>        Marker:0x15dd0350.marker{id: 138}

    Integralization Adjustments:
         (none)

    Statistics:
    4 rows. Variable counts:
            1 ->   2
            2 ->   2
}: internal error.  Cannot find an outgoing row head for incoming head UIView:0x170c6e40.Height{id: 1091}, which should never happen.

真正让我感到困惑的是最后一行,“内部错误......永远不会发生。”

我很好奇是否有其他人遇到过这个错误,以及他们是如何解决的。

  • 这是初始化变量 currentView 的问题,还是与 AppDelegate 的 window 变量有关?

  • 这真的是故事板约束的问题吗?如果是这样,我可以/应该在单个屏幕上放置的约束数量是否有限制?


编辑:

我发现这个错误实际上只是在离开一个特定的故事板时才引起的。屏幕上的约束引发了错误。所以我在 changeController 中添加了一些代码:以编程方式从每个子视图中删除约束,然后从父视图中删除每个子视图。

当有问题的 UIViewController 中的约束被清除并重新创建时,问题最终得到解决。

感谢您的所有帮助和建议。

4

0 回答 0