2014-11-02 37 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