iOS8中的Autolayout崩溃

时间:2015-02-25 20:51:45

标签: ios objective-c uiscrollview autolayout

UIScrollView编辑方式将子视图添加到xib并启用autolayout。接收崩溃:

2015-02-25 22:21:25.829 EAIntroView[5215:1435025] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010c1f4f35 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010be8dbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010c0dff33 -[__NSArrayM objectAtIndex:] + 227
    3   UIKit                               0x000000010c87b5b1 _UIViewTopDownSubtreeTraversal + 193
    4   UIKit                               0x000000010ceacee6 -[UIView(UIConstraintBasedLayout_EngineDelegate) _invalidateSystemLayoutSizeFittingSizeAtEngineDelegateLevel] + 128
    5   Foundation                          0x000000010ba319bf -[NSISEngine tryToAddConstraintWithMarker:expression:integralizationAdjustment:mutuallyExclusiveConstraints:] + 915
    6   Foundation                          0x000000010bbbb0f8 -[NSLayoutConstraint _addLoweredExpression:toEngine:integralizationAdjustment:lastLoweredConstantWasRounded:mutuallyExclusiveConstraints:] + 275
    7   Foundation                          0x000000010ba2611a -[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] + 220
    8   UIKit                               0x000000010cea9de5 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 474
    9   Foundation                          0x000000010ba33d6e -[NSISEngine withBehaviors:performModifications:] + 155
    10  UIKit                               0x000000010cea9beb __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 452
    11  UIKit                               0x000000010cea99fe -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 197
    12  UIKit                               0x000000010cea9ce4 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 217
    13  Foundation                          0x000000010ba33d6e -[NSISEngine withBehaviors:performModifications:] + 155
    14  UIKit                               0x000000010cea9beb __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 452
    15  UIKit                               0x000000010cea99fe -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 197
    16  UIKit                               0x000000010cea9ce4 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 217
    17  Foundation                          0x000000010ba33d6e -[NSISEngine withBehaviors:performModifications:] + 155
    18  UIKit                               0x000000010cea9beb __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 452
    19  UIKit                               0x000000010cea99fe -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 197
    20  UIKit                               0x000000010c8a568b -[UIScrollView _switchToLayoutEngine:] + 69
    21  UIKit                               0x000000010cea9ce4 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 217
    22  Foundation                          0x000000010ba33d6e -[NSISEngine withBehaviors:performModifications:] + 155
    23  UIKit                               0x000000010cea9beb __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 452
    24  UIKit                               0x000000010cea99fe -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 197
    25  UIKit                               0x000000010cea9ce4 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 217
    26  Foundation                          0x000000010ba33d6e -[NSISEngine withBehaviors:performModifications:] + 155
    27  UIKit                               0x000000010cea9beb __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 452
    28  UIKit                               0x000000010cea99fe -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 197
    29  UIKit                               0x000000010cea9671 -[UIView(AdditionalLayoutSupport) _initializeHostedLayoutEngine] + 404
    30  UIKit                               0x000000010ce9e591 -[UIView(UIConstraintBasedLayout) _layoutEngine_windowDidChange] + 127
    31  UIKit                               0x000000010c8984a5 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 207
    32  UIKit                               0x000000010c891112 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 125
    33  UIKit                               0x000000010c891086 -[UIView(Hierarchy) _postMovedFromSuperview:] + 437
    34  UIKit                               0x000000010c89af4b -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1604
    35  UIKit                               0x000000010cabfe84 -[UILayoutContainerView addSubview:] + 75
    36  EAIntroView                         0x000000010b93e14a -[EAIntroView showInView:animateDuration:withInitialPageIndex:] + 362
    37  EAIntroView                         0x000000010b93dfc9 -[EAIntroView showInView:animateDuration:] + 121
    38  EAIntroView                         0x000000010b9303a7 -[ViewController showIntroWithCustomViewFromNib] + 1879
    39  EAIntroView                         0x000000010b9326a4 -[ViewController tableView:didSelectRowAtIndexPath:] + 340
    40  UIKit                               0x000000010c90c393 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1293
    41  UIKit                               0x000000010c90c4d4 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219
    42  UIKit                               0x000000010c847331 _applyBlockToCFArrayCopiedToStack + 314
    43  UIKit                               0x000000010c8471ab _afterCACommitHandler + 516
    44  CoreFoundation                      0x000000010c129dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    45  CoreFoundation                      0x000000010c129d20 __CFRunLoopDoObservers + 368
    46  CoreFoundation                      0x000000010c11fb53 __CFRunLoopRun + 1123
    47  CoreFoundation                      0x000000010c11f486 CFRunLoopRunSpecific + 470
    48  GraphicsServices                    0x00000001106f59f0 GSEventRunModal + 161
    49  UIKit                               0x000000010c824420 UIApplicationMain + 1282
    50  EAIntroView                         0x000000010b932843 main + 115
    51  libdyld.dylib                       0x000000010e9c7145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

xib中是否存在任何自动布局限制并不重要。将自动布局约束添加到以编程方式创建的子视图(不包含xib) - 会导致同样的崩溃。

但是:如果我们创建并显示自定义视图而不进行任何自动布局,请隐藏它并使用autolayout xib创建新视图 - 即使所有约束都有效,它也能正常工作。

相关问题:NSRangeException on iOS 8

该问题的解决方案:

  

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

GitHub上的所有代码,示例项目和相关问题:https://github.com/ealeksandrov/EAIntroView/issues/100

1 个答案:

答案 0 :(得分:0)

我终于找到了这个问题的根本原因:我的subviews子类(EARestrictedScrollView.m#L54-56)中的UIScrollView属性覆盖。

Autolayout以某种方式使用子视图属性并覆盖它会破坏事物。这是不一致的,取决于许多其他事情,但修复subviews在100%的情况下为我处理。