xcode '无法在 descriptionForLayoutAttribute_layoutItem_coefficient 中创建描述。什么是零

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26024906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:41:15  来源:igfitidea点击:

'Unable to create description in descriptionForLayoutAttribute_layoutItem_coefficient. Something is nil'

iosobjective-cxcodeautolayout

提问by Kyle KIM

First, I got 3 different UIViews to replace the detail view in Split View Controller on iPad storyboard

首先,我有 3 个不同的 UIViews 来替换 iPad storyboard 上拆分视图控制器中的详细视图

It runs on well on iOS8 iPad. But when I load one of the detail views, the app crashes when running in iOS7 and iOS 6 Simulator.

它在 iOS8 iPad 上运行良好。但是当我加载其中一个细节视图时,应用程序在 iOS7 和 iOS 6 Simulator 中运行时崩溃。

I only assume it is because of Auto layout on my Storyboard.

我只认为这是因为我的故事板上的自动布局。

Does anyone know how to fix it?

有谁知道如何修理它?

2014-09-25 04:15:19.705 PSTappsperance[48327:60b] Pad AppDelegate ########
2014-09-25 04:15:27.869 PSTappsperance[48327:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to create description in descriptionForLayoutAttribute_layoutItem_coefficient. Something is nil'
*** First throw call stack:
(
0   CoreFoundation                      0x0000000110a5c495 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x00000001107af99e objc_exception_throw + 43
2   CoreFoundation                      0x0000000110a5c2ad +[NSException raise:format:] + 205
3   Foundation                          0x00000001104ec548 descriptionForLayoutAttribute_layoutItem_coefficient + 145
4   Foundation                          0x00000001104ec3bc -[NSLayoutConstraint equationDescription] + 216
5   Foundation                          0x00000001104ec831 -[NSLayoutConstraint description] + 297
6   CoreFoundation                      0x0000000110a1d1b9 -[NSArray descriptionWithLocale:indent:] + 345
7   Foundation                          0x000000011037e14e _NSDescriptionWithLocaleFunc + 64
8   CoreFoundation                      0x00000001109e1244 __CFStringAppendFormatCore + 7252
9   CoreFoundation                      0x0000000110a1f913 _CFStringCreateWithFormatAndArgumentsAux + 115
10  CoreFoundation                      0x0000000110a7fa5b _CFLogvEx + 123
11  Foundation                          0x00000001103ae276 NSLogv + 79
12  Foundation                          0x00000001103ae20a NSLog + 148
13  UIKit                               0x000000010f927097 -[UIView(UIConstraintBasedLayout_EngineDelegate) engine:willBreakConstraint:dueToMutuallyExclusiveConstraints:] + 62
14  Foundation                          0x00000001104e32ac -[NSISEngine handleUnsatisfiableRowWithHead:body:usingInfeasibilityHandlingBehavior:mutuallyExclusiveConstraints:] + 521
15  Foundation                          0x00000001104e49b1 -[NSISEngine tryUsingArtificialVariableToAddConstraintWithMarker:rowBody:usingInfeasibilityHandlingBehavior:mutuallyExclusiveConstraints:] + 353
16  Foundation                          0x000000011039c26b -[NSISEngine tryToAddConstraintWithMarker:expression:integralizationAdjustment:mutuallyExclusiveConstraints:] + 663
17  Foundation                          0x00000001104ed180 -[NSLayoutConstraint _addLoweredExpression:toEngine:integralizationAdjustment:lastLoweredConstantWasRounded:mutuallyExclusiveConstraints:] + 275
18  Foundation                          0x00000001103981b0 -[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] + 204
19  UIKit                               0x000000010f923f41 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 413
20  Foundation                          0x00000001104e529a -[NSISEngine withBehaviors:performModifications:] + 119
21  UIKit                               0x000000010f923d7d __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 401
22  UIKit                               0x000000010f923bc3 -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 197
23  UIKit                               0x000000010f923e57 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 179
24  Foundation                          0x00000001104e529a -[NSISEngine withBehaviors:performModifications:] + 119
25  UIKit                               0x000000010f923d7d __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 401
26  UIKit                               0x000000010f923bc3 -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 197
27  UIKit                               0x000000010f3ab975 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 95
28  Foundation                          0x00000001104e529a -[NSISEngine withBehaviors:performModifications:] + 119
29  UIKit                               0x000000010f3ab889 -[UIView(Hierarchy) _postMovedFromSuperview:] + 321
30  UIKit                               0x000000010f3b52ac -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1508
31  UIKit                               0x000000010f632778 -[UINavigationTransitionView transition:fromView:toView:] + 454
32  UIKit                               0x000000010f6325b0 -[UINavigationTransitionView transition:toView:] + 25
33  UIKit                               0x000000010f46f4d7 -[UINavigationController _startTransition:fromViewController:toViewController:] + 2893
34  UIKit                               0x000000010f46f787 -[UINavigationController _startDeferredTransitionIfNeeded:] + 547
35  UIKit                               0x000000010f470238 -[UINavigationController __viewWillLayoutSubviews] + 43
36  UIKit                               0x000000010f58a895 -[UILayoutContainerView layoutSubviews] + 202
37  UIKit                               0x000000010f3b7993 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 354
38  QuartzCore                          0x000000011427c802 -[CALayer layoutSublayers] + 151
39  QuartzCore                          0x0000000114271369 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363
40  QuartzCore                          0x00000001142711ea _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
41  QuartzCore                          0x00000001141e4fb8 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 252
42  QuartzCore                          0x00000001141e6030 _ZN2CA11Transaction6commitEv + 394
43  QuartzCore                          0x00000001141e669d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
44  CoreFoundation                      0x0000000110a27dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
45  CoreFoundation                      0x0000000110a27d37 __CFRunLoopDoObservers + 391
46  CoreFoundation                      0x0000000110a07522 __CFRunLoopRun + 946
47  CoreFoundation                      0x0000000110a06d83 CFRunLoopRunSpecific + 467
48  GraphicsServices                    0x0000000112dbdf04 GSEventRunModal + 161
49  UIKit                               0x000000010f357e33 UIApplicationMain + 1010
50  PSTappsperance                      0x000000010f092653 main + 115
51  libdyld.dylib                       0x00000001114b05fd start + 1
52  ???                                 0x0000000000000001 0x0 + 1
)libc++abi.dylib: terminating with uncaught exception of type NSException

采纳答案by Kyle KIM

Solved. It was because of Auto Layout constraints.

解决了。这是因为自动布局的限制。

There were Labels that did not know to determine its width.

有些标签不知道确定其宽度。

But why only works on iOS 8? I pinned two constraints to determine the width in Xcode 6

但为什么只适用于 iOS 8?我固定了两个约束来确定 Xcode 6 中的宽度

Trailing Space to: superview
Leading Space to: superview

when pinning constraints, there is an option 'Constraint to Margin', which is checked by default in Xcode 6. And Older versions does not support that.

固定约束时,有一个选项“Constraint to Margin”,在 Xcode 6 中默认选中。旧版本不支持。

回答by skywinder

This crash appears when you run your app with Marginsand baselinesin constraints on iOS 7.

当你运行你的应用程序会出现这种崩溃边距基线上的约束iOS 7

To find and remove all dummy constraints strings you can do this:

要查找并删除所有虚拟约束字符串,您可以执行以下操作:

Xcodedoesn't highlight all these constraints correctly in Interface Builder, so you can use this solution:

Xcode中没有正确突出显示所有这些约束Interface Builder,因此您可以使用此解决方案:

  1. Close Xcode
  2. Open your storyboard file in your favorite text editor
  3. Find all occurrences using the regex: (\w)Margin"and replace all of them with the pattern: \1"(the regex version is the one used in Sublime 2)
  4. Find and remove from the storyboard file all the strings using the pattern: .*"baseline".*\n
  5. Now save the file and open it in Xcode
  6. Fix all appeared misaligns: find all warnings and press _"Update constraints for all views" to save the original position of all the views.
  7. Profit!
  1. 关闭 Xcode
  2. 在您喜欢的文本编辑器中打开您的故事板文件
  3. 使用正则表达式查找所有出现的事件:(\w)Margin"并将它们全部替换为模式:(\1"正则表达式版本是 Sublime 2 中使用的版本)
  4. 使用模式从故事板文件中查找并删除所有字符串: .*"baseline".*\n
  5. 现在保存文件并打开它 Xcode
  6. 修复所有出现的未对齐:找到所有警告并按_“更新所有视图的约束”以保存所有视图的原始位置。
  7. 利润!


Update:I found that "baseline" constraints causes crashes also, but Xcode doesn't show any warnings about these constrains!

更新:我发现“基线”约束也会导致崩溃,但 Xcode 没有显示关于这些约束的任何警告!

回答by Saurabh Shukla

You are right @Kyle. This is causing due to Auto Layout constraints. @Mazen, In my case too it was "First Baseline Alignment", removed it and worked. Here are some checks to detect/solve the problem.

你是对的@Kyle。这是由于自动布局约束造成的。@Mazen,在我的情况下也是“第一基线对齐”,将其删除并起作用。这里有一些检查来检测/解决问题。

  1. To detect which storyboard causing this error you can perform a quick check. In "File Inspector", Uncheck the "Use Auto Layout" for the selected storyboard. Now, clean and build your application. If still getting the same error means the constraint causing this error is in another storyboard or in code.

  2. Once you identify the storyboard, resolve the errors and warnings displayed by storyboard using Add Missing Constraints or other similar options.

  3. To filter which constraint causing this error. Remove 3-4 constraints at a time(you can remove more to make it fast) to check if the error resolved. Once error resolved, identify the exact constraint which was causing this error.

  4. Regarding "Constraint to Margin". In my case this is checked in few constraints but its not causing any error/warning below iOS8.

  5. You can use this link to resolve auto layout issues. Resolving Auto Layout Issues

  1. 要检测导致此错误的故事板,您可以执行快速检查。在“文件检查器”中,取消选中所选故事板的“使用自动布局”。现在,清理并构建您的应用程序。如果仍然出现相同的错误,则意味着导致此错误的约束在另一个故事板或代码中。

  2. 确定故事板后,使用添加缺失约束或其他类似选项解决故事板显示的错误和警告。

  3. 过滤导致此错误的约束。一次删除 3-4 个约束(您可以删除更多以使其更快)以检查错误是否已解决。错误解决后,确定导致此错误的确切约束。

  4. 关于“保证金限制”。在我的情况下,这是在几个约束中检查的,但它不会导致任何低于 iOS8 的错误/警告。

  5. 您可以使用此链接解决自动布局问题。解决自动布局问题

Hope this will help someone.

希望这会帮助某人。