我已经在我的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.
这是真正让我感到困惑的最后一行,&#34;内部错误....这应该永远不会发生。&#34;
我很好奇是否有其他人遇到过这个错误,以及他们是如何处理这个错误的。
这是初始化变量currentView的问题,还是与AppDelegate的窗口变量有关?
这是故事板限制的问题吗?如果是这样,我可以/应该放在一个屏幕上的限制数量是否有限制?
编辑:
我发现错误实际上只是在导航离开某个特定故事板时引起的。屏幕上的约束是抛出错误。 所以我在changeController中添加了一些代码:以编程方式从每个子视图中删除约束,然后从superview中删除每个子视图。
当清除并重新创建违规UIViewController中的约束时,问题最终得到解决。
感谢您的所有帮助和建议。