我将 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 解决了这个问题。