簡體   English   中英

iOS8中的自動布局崩潰

[英]Autolayout crash in iOS8

xib autolayout打開的情況下,以編程方式從xib將子視圖添加到UIScrollView 接收崩潰:

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 )會導致相同的崩潰。

但是:如果我們創建並顯示沒有任何自動布局的自定義視圖,請將其隱藏並使用自動布局xib創建新xib -即使在所有約束都起作用的情況下,它也將完美運行。

相關的問題: iOS 8上的NSRangeException

該問題的解決方案:

為我的所有XIB關閉AutoLayout可解決此問題。

GitHub上的所有代碼,示例項目和相關問題: https//github.com/ealeksandrov/EAIntroView/issues/100

我終於找到了這個問題的根本原因: subviews屬性重寫我UIScrollView子類( EARestrictedScrollView.m#L54-56 )。

自動布局以某種方式使用subview屬性,並且覆蓋它會破壞事情。 這是不一致的,並且取決於許多其他因素,但是在100%的情況下,修復subviews對我來說都是如此。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM