Crashes as soon as I add autolayout constraints on storyboard
If I add Layout constraints I get the following error:
2014-07-20 22:07:48.231 cookpad-global-ios[4182:86745] -[UILabel length]: unrecognized selector sent to instance 0x7f9b5a5ac9f0 2014-07-20 22:07:48.235 cookpad-global-ios[4182:86745] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel length]: unrecognized selector sent to instance 0x7f9b5a5ac9f0' *** First throw call stack: ( 0 CoreFoundation 0x000000010f493055 exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010f140a1c objc_exception_throw + 45 2 CoreFoundation 0x000000010f499f1d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x000000010f3f2dbc __forwarding + 988 4 CoreFoundation 0x000000010f3f2958 _CF_forwarding_prep_0 + 120 5 UIKit 0x000000010e0cdee1 _truncatedDebuggingDescriptionForLayout + 23 6 UIKit 0x000000010e0da44e -[UIView(AdditionalLayoutSupport) _defaultLayoutDescription] + 39 7 Foundation 0x000000010ee724d4 descriptionForLayoutAttribute_layoutItem_coefficient + 92 8 Foundation 0x000000010ee722f9 -[NSLayoutConstraint equationDescription] + 77 9 Foundation 0x000000010ee727f8 -[NSLayoutConstraint description] + 284 10 CoreFoundation 0x000000010f4853a6 -[NSArray descriptionWithLocale:indent:] + 358 11 Foundation 0x000000010ecbd5f6 _NSDescriptionWithLocaleFunc + 64 12 CoreFoundation 0x000000010f38e7fd __CFStringAppendFormatCore + 9645 13 CoreFoundation 0x000000010f473720 _CFStringCreateWithFormatAndArgumentsAux2 + 256 14 CoreFoundation 0x000000010f4826df _CFLogvEx2 + 127 15 Foundation 0x000000010ece3de2 NSLogv + 99 16 Foundation 0x000000010ece3d67 NSLog + 148 17 Foundation 0x000000010ee6c23f -[NSISEngine handleUnsatisfiableRowWithHead:body:usingInfeasibilityHandlingBehavior:mutuallyExclusiveConstraints:] + 492 18 Foundation 0x000000010ee6c964 -[NSISEngine tryUsingArtificialVariableToAddConstraintWithMarker:rowBody:usingInfeasibilityHandlingBehavior:mutuallyExclusiveConstraints:] + 382 19 Foundation 0x000000010eced8aa -[NSISEngine tryToAddConstraintWithMarker:expression:integralizationAdjustment:mutuallyExclusiveConstraints:] + 691 20 Foundation 0x000000010ee731bb -[NSLayoutConstraint _addLoweredExpression:toEngine:integralizationAdjustment:lastLoweredConstantWasRounded:mutuallyExclusiveConstraints:] + 275 21 Foundation 0x000000010ece1f3d -[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] + 220 22 UIKit 0x000000010e0ce69a -[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 462 23 UIKit 0x000000010e0ce934 -[UIView(UIConstraintBasedLayout) _tryToAddConstraintWithoutUpdatingConstraintsArray:roundingAdjustment:mutuallyExclusiveConstraints:] + 30 24 UIKit 0x000000010e0cea5c -[UIView(UIConstraintBasedLayout) _tryToAddConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 243 25 UIKit 0x000000010e0ced9b __50-[UIView(UIConstraintBasedLayout) addConstraints:]_block_invoke + 188 26 Foundation 0x000000010ecefd29 -[NSISEngine withBehaviors:performModifications:] + 150 27 UIKit 0x000000010e0cecd0 -[UIView(UIConstraintBasedLayout) addConstraints:] + 263 28 UIKit 0x000000010e0d0219 -[UIView(UIConstraintBasedLayout) _updateLayoutEngineHostConstraints] + 492 29 UIKit 0x000000010e0da1b8 -[UIView(AdditionalLayoutSupport) updateConstraints] + 43 30 UIKit 0x000000010e0d971a -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 243 31 Foundation 0x000000010ecefd29 -[NSISEngine withBehaviors:performModifications:] + 150 32 UIKit 0x000000010e0d991a -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 124 33 UIKit 0x000000010e0d9dde __60-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded]_block_invoke + 96 34 Foundation 0x000000010ecefd29 -[NSISEngine withBehaviors:performModifications:] + 150 35 UIKit 0x000000010e0d9aa6 -[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded] + 231 36 UIKit 0x000000010e0da308 -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeeded] + 159 37 UIKit 0x000000010dada22d -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 114 38 UIKit 0x000000010dae5ebd -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 519 39 QuartzCore 0x000000010f973598 -[CALayer layoutSublayers] + 150 40 QuartzCore 0x000000010f9681be _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380 41 QuartzCore 0x000000010f96802e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 42 QuartzCore 0x000000010f8d6f16 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242 43 QuartzCore 0x000000010f8d8022 _ZN2CA11Transaction6commitEv + 390 44 QuartzCore 0x000000010f8d868d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89 45 CoreFoundation 0x000000010f3c8927 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23 46 CoreFoundation 0x000000010f3c8880 __CFRunLoopDoObservers + 368 47 CoreFoundation 0x000000010f3be0d3 __CFRunLoopRun + 1123 48 CoreFoundation 0x000000010f3bda06 CFRunLoopRunSpecific + 470 49 GraphicsServices 0x0000000112402abf GSEventRunModal + 161 50 UIKit 0x000000010da6dcf8 UIApplicationMain + 1282 51 cookpad-global-ios 0x000000010d36ca63 main + 115 52 libdyld.dylib 0x000000010fd29145 start + 1 53 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException
As soon as I remove all constraints it works great, but then the texts inside my cell are not well aligned.
I have seen this crash in unrelated code. In my cases (and it happened in several places), I traced it to needing to clear the translatesAutoresizingMaskIntoConstraints flag on the child view. I had previously done that on the hosting / parent view, but that was not the issue. Evidently there is a crash bug in auto layout's logging facility, as evidenced in your stack trace. And for all it's worth, I had the same stack trace.
Here is a code snippet. Note that you can diagnose this issue by logging the constraints.
Crashes when the following two lines are disabled
// self.graphView.setTranslatesAutoresizingMaskIntoConstraints(false) // self.graphView.removeConstraints(self.constraints())
// configure layout constraints
let metrics = [ "margin":16 ]
let views = [ "graph":self.graphView ]
self.addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat("V:|-[graph]-|",
options: nil, metrics:metrics, views:views)
+ NSLayoutConstraint.constraintsWithVisualFormat("H:|-[graph]-|",
options: nil, metrics:metrics, views:views)
)
for constraint in self.constraints() as [NSLayoutConstraint] {
println("constraint: \(constraint)")
}