1

我将 XCode 5 升级到 6 以在 iPhone 6 和 6 Plus 上测试我的项目,并且在启动时遇到了神秘的崩溃:

'*** -[__NSArrayM objectAtIndex:]: index 4 beyond bounds [0 .. 3]'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010569b3f5 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000104b20bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x00000001055864d3 -[__NSArrayM objectAtIndex:] + 227
    3   UIKit                               0x00000001028164e1 _UIViewTopDownSubtreeTraversal + 193
    4   UIKit                               0x0000000102e43286 -[UIView(UIConstraintBasedLayout_EngineDelegate) _invalidateSystemLayoutSizeFittingSizeAtEngineDelegateLevel] + 128
    5   Foundation                          0x0000000103aa66df -[NSISEngine tryToAddConstraintWithMarker:expression:integralizationAdjustment:mutuallyExclusiveConstraints:] + 915
    6   Foundation                          0x0000000103c2f678 -[NSLayoutConstraint _addLoweredExpression:toEngine:integralizationAdjustment:lastLoweredConstantWasRounded:mutuallyExclusiveConstraints:] + 275
    7   Foundation                          0x0000000103a9ae3a -[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] + 220
    8   UIKit                               0x0000000102e40495 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 474
    9   Foundation                          0x0000000103aa8a8e -[NSISEngine withBehaviors:performModifications:] + 155
    10  UIKit                               0x0000000102e4029b __57-[UIView(AdditionalLayoutSupport) 

经过大量的试验和错误并在各种配置中尝试各种 XIB 后,问题出现了,因为我在打开自动布局的情况下混合了一些 XIB,包含关闭自动布局的其他 UIView(基于 XIB)。

为我所有的 XIB 关闭 AutoLayout 解决了这个问题。

4

2 回答 2

0

Faced the same issue. Found that the problem is in button whose layer was used as mask for another button's layer for some visual effect (CALayer's mask property). Removing mask button from view hierarchy fixed the problem. I just moved it to view controller scene in storyboard.

Looks like using layer as a mask caused problem in _UIViewTopDownSubtreeTraversal function used by autolayout. Maybe other layer manipulations for some view also can.

于 2014-09-24T16:47:19.600 回答
0

我发现的一种解决方案是,您需要至少有 6 个屏幕,然后应用程序就不会崩溃。

仍然试图让它在更少的屏幕上工作。在我唯一的 XIB (LaunchScreen.xib) 上关闭了自动布局,但这并没有解决问题。

于 2015-05-02T14:19:10.003 回答