2014-11-02 39 views
1

發生以下故障。 Xcode不會報告任何缺少的約束(有意義),並且每次都不會發生崩潰。 顯然我有一個地方的錯誤 - 但我從哪裏開始調查?iOS自動佈局崩潰 - 我從哪裏開始?

編輯

所以破例斷點後 - 我看到崩潰線程即自動佈局代碼。 不同的線程有以下幾種: enter image description here

不令人震驚的是,這是一個UILabel的大小 - 現在呢?

崩潰轉儲:

RemoveVariableFromSortedPriorityVectorList(NSISObjectiveLinearExpression *, NSISVariable *)(), /SourceCache/Foundation_Sim/Foundation-1047.25/Layout.subproj/IncrementalSimplex/NSISObjectiveLinearExpression.m:136 
2014-11-03 00:28:14.899 Cookila copy[3470:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Missing variable UILabel:0x78885670.Width{id: 5777} in variablesSortedByPriorityVectors' 
*** First throw call stack: 
(
    0 CoreFoundation      0x03ba91e4 __exceptionPreprocess + 180 
    1 libobjc.A.dylib      0x0386a8e5 objc_exception_throw + 44 
    2 CoreFoundation      0x03ba9048 +[NSException raise:format:arguments:] + 136 
    3 Foundation       0x03307b20 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 101 
    4 Foundation       0x03414df4 RemoveVariableFromSortedPriorityVectorList + 386 
    5 Foundation       0x0329af95 -[NSISObjectiveLinearExpression removeVariable:] + 30 
    6 Foundation       0x034152b9 -[NSISObjectiveLinearExpression replaceVariable:withExpression:processVariableNewToReceiver:processVariableDroppedFromReceiver:] + 76 
    7 Foundation       0x0329b3f7 -[NSISEngine substituteOutAllOccurencesOfBodyVar:withExpression:] + 897 
    8 Foundation       0x0340b5cf -[NSISEngine pivotToMakeBodyVar:newHeadOfRowWithHead:andDropRow:] + 421 
    9 Foundation       0x0329a098 -[NSISEngine minimizeConstantInObjectiveRowWithHead:] + 287 
    10 Foundation       0x0340db9d -[NSISEngine tryUsingArtificialVariableToAddConstraintWithMarker:rowBody:usingInfeasibilityHandlingBehavior:mutuallyExclusiveConstraints:] + 300 
    11 Foundation       0x03298fc3 -[NSISEngine tryToAddConstraintWithMarker:expression:integralizationAdjustment:mutuallyExclusiveConstraints:] + 780 
    12 Foundation       0x03417a77 -[NSLayoutConstraint _addLoweredExpression:toEngine:integralizationAdjustment:lastLoweredConstantWasRounded:mutuallyExclusiveConstraints:] + 283 
    13 Foundation       0x03294596 -[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] + 252 
    14 UIKit        0x029ac30d -[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 451 
    15 UIKit        0x029ada4b -[UIView(UIConstraintBasedLayout) _constraints_didChangeAutoresizingConstraintsArrayForContainedView:] + 233 
    16 UIKit        0x029ad60e -[UIView(UIConstraintBasedLayout) _setAutoresizingConstraints:] + 240 
    17 UIKit        0x029adea0 -[UIView(UIConstraintBasedLayout) _updateAutoresizingConstraints] + 117 
    18 UIKit        0x029b77bf -[UIView(AdditionalLayoutSupport) updateConstraints] + 110 
    19 UIKit        0x029b7058 -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 239 
    20 UIKit        0x029b71d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122 
    21 UIKit        0x029b7157 __UIViewRecursionHelper + 40 
    22 CoreFoundation      0x03b4ac69 CFArrayApplyFunction + 57 
    23 UIKit        0x029b6ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147 
    24 UIKit        0x029b71d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122 
    25 UIKit        0x029b7157 __UIViewRecursionHelper + 40 
    26 CoreFoundation      0x03b4ac69 CFArrayApplyFunction + 57 
    27 UIKit        0x029b6ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147 
    28 UIKit        0x029b71d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122 
    29 UIKit        0x029b7157 __UIViewRecursionHelper + 40 
    30 CoreFoundation      0x03b4ac69 CFArrayApplyFunction + 57 
    31 UIKit        0x029b6ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147 
    32 UIKit        0x029b71d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122 
    33 UIKit        0x029b7157 __UIViewRecursionHelper + 40 
    34 CoreFoundation      0x03b4ac69 CFArrayApplyFunction + 57 
    35 UIKit        0x029b6ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147 
    36 UIKit        0x029b71d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122 
    37 UIKit        0x029b7157 __UIViewRecursionHelper + 40 
    38 CoreFoundation      0x03b4ac69 CFArrayApplyFunction + 57 
    39 UIKit        0x029b6ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147 
    40 UIKit        0x029b71d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122 
    41 UIKit        0x029b7157 __UIViewRecursionHelper + 40 
    42 CoreFoundation      0x03b4ac69 CFArrayApplyFunction + 57 
    43 UIKit        0x029b6ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147 
    44 UIKit        0x029b71d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122 
    45 UIKit        0x029b7157 __UIViewRecursionHelper + 40 
    46 CoreFoundation      0x03b4ac69 CFArrayApplyFunction + 57 
    47 UIKit        0x029b6ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147 
    48 UIKit        0x029b71d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122 
    49 UIKit        0x029b7157 __UIViewRecursionHelper + 40 
    50 CoreFoundation      0x03b4ac69 CFArrayApplyFunction + 57 
    51 UIKit        0x029b6ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147 
    52 UIKit        0x029b71d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122 
    53 UIKit        0x029b7157 __UIViewRecursionHelper + 40 
    54 CoreFoundation      0x03b4ac69 CFArrayApplyFunction + 57 
    55 UIKit        0x029b6ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147 
    56 UIKit        0x029b71d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122 
    57 UIKit        0x029ab878 __62-[UIWindow(UIConstraintBasedLayout) updateConstraintsIfNeeded]_block_invoke + 43 
    58 Foundation       0x0340e68c -[NSISEngine withBehaviors:performModifications:] + 107 
    59 Foundation       0x0329e3c5 -[NSISEngine withAutomaticOptimizationDisabled:] + 48 
    60 UIKit        0x029ab590 -[UIWindow(UIConstraintBasedLayout) updateConstraintsIfNeeded] + 225 
    61 UIKit        0x029b7836 -[UIView(AdditionalLayoutSupport) _updateConstraintsAtWindowLevelIfNeeded] + 85 
    62 UIKit        0x0237b324 -[UIView(Hierarchy) layoutSubviews] + 62 
    63 UIKit        0x02388964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355 
    64 libobjc.A.dylib      0x0387c82b -[NSObject performSelector:withObject:] + 70 
    65 QuartzCore       0x021f045a -[CALayer layoutSublayers] + 148 
    66 QuartzCore       0x021e4244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380 
    67 QuartzCore       0x021e40b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26 
    68 QuartzCore       0x0214a7fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294 
    69 QuartzCore       0x0214bb85 _ZN2CA11Transaction6commitEv + 393 
    70 QuartzCore       0x0214c258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92 
    71 CoreFoundation      0x03b7136e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30 
    72 CoreFoundation      0x03b712bf __CFRunLoopDoObservers + 399 
    73 CoreFoundation      0x03b4f254 __CFRunLoopRun + 1076 
    74 CoreFoundation      0x03b4e9d3 CFRunLoopRunSpecific + 467 
    75 CoreFoundation      0x03b4e7eb CFRunLoopRunInMode + 123 
    76 GraphicsServices     0x045815ee GSEventRunModal + 192 
    77 GraphicsServices     0x0458142b GSEventRun + 104 
    78 UIKit        0x02319f9b UIApplicationMain + 1225 
    79 Cookila copy      0x000e594d main + 141 
    80 libdyld.dylib      0x0415b701 start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
+0

添加一個異常斷點,並告訴我們的代碼是什麼,都崩潰了。 – Fogmeister 2014-11-02 22:42:00

+0

你可以添加左側面板的打印嗎?所以我們可以看到函數路徑? – 2014-11-02 22:44:15

+0

看起來這裏的_real_問題是遞歸。我的猜測是你有某種循環:約束A依賴於約束B,約束A ......但這只是一個猜測。 – matt 2014-11-02 22:50:36

回答

0

那麼,如果它是一個UILabel你對我的限制會嘗試刪除它有限制,調整其大小,然後設置新的限制(即使它們的大小調整和以前一樣)。您可以編輯/重寫該方法來重新調用標籤刪除和重新添加約束。

代碼:

[label autoRemoveConstraintsAffectingView]; 
//Resize 
//Add constraints 
[self.view needsUpdateConstraints]; 
[self.view layoutIfNeeded]; 
+0

我刪除了我曾經有過的sizetofit ...仍然發生這種情況(每10次運行一次,grr ....) - 我有選項可以理解哪個是導致問題的控制/約束? (假設我有「異常斷點」,並且有整個堆棧線程) – Boaz 2014-11-03 14:54:05

+0

通常,xCode會在您設置無法完成的約束或缺少鍵約束時記錄日誌。我建議你看一下https://github.com/smileyborg/PureLayout,它在處理約束問題時效率更高,編寫代碼更短,並且比Apple的默認更直觀。它甚至有崩潰的方法,可以準確地告訴你問題是什麼。 – 2014-11-03 15:47:36

+0

事情是所有的佈局完成在XIB /故事板:( – Boaz 2014-11-03 16:05:11