ios - 跟踪 NSLayoutConstraint 崩溃?

标签 ios objective-c stack nslayoutconstraint

我对某些 NSLayoutConstraint 设置有疑问,这些设置来自 iOS9(我认为)。无论如何,我收到以下控制台错误:

This NSLayoutConstraint is being configured with a constant that exceeds internal limits. A smaller value will be substituted, but this problem should be fixed. Break on void _NSLayoutConstraintNumberExceedsLimit() to debug. This will be logged only once. This may break in the future.

其次是:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* +[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]: A constraint cannot be made between a leading/trailing attribute and a right/left attribute. Use leading/trailing for both or neither.'

然后是一堆堆栈信息:

*** First throw call stack:
(
    0   CoreFoundation                      0x0000000102b3af65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001025aedeb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000102b3ae9d +[NSException raise:format:] + 205
    3   Foundation                          0x0000000102177e82 +[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:] + 299
    4   My App                            0x000000010011f429 -[APStatisticsAverageFlightDuration viewDidInit] + 2841
    5   My App                            0x000000010011e909 -[APStatisticsAverageFlightDuration awakeFromNib] + 73
    6   UIKit                               0x000000010328752e -[UINib instantiateWithOwner:options:] + 2416
    7   UIKit                               0x000000010307284d -[UIViewController _loadViewFromNibNamed:bundle:] + 381
    8   UIKit                               0x0000000103073179 -[UIViewController loadView] + 178
    9   UIKit                               0x00000001032aad85 -[UITableViewController loadView] + 84
    10  UIKit                               0x000000010307347c -[UIViewController loadViewIfRequired] + 139
    11  UIKit                               0x0000000103073c7d -[UIViewController view] + 27
    12  UIKit                               0x00000001037ded8e __67-[UIStoryboardEmbedSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 524
    13  UIKit                               0x00000001035cf189 -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 460
    14  UIKit                               0x00000001035cef8c -[UIStoryboardSegueTemplate _perform:] + 82
    15  UIKit                               0x00000001035cf250 -[UIStoryboardSegueTemplate perform:] + 156
    16  UIKit                               0x0000000103073687 -[UIViewController loadViewIfRequired] + 662
    17  UIKit                               0x00000001030b6c26 -[UINavigationController _layoutViewController:] + 54
    18  UIKit                               0x00000001030b74dd -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 433
    19  UIKit                               0x00000001030b7633 -[UINavigationController _startTransition:fromViewController:toViewController:] + 116
    20  UIKit                               0x00000001030b8879 -[UINavigationController _startDeferredTransitionIfNeeded:] + 890
    21  UIKit                               0x00000001030b967d -[UINavigationController __viewWillLayoutSubviews] + 57
    22  UIKit                               0x000000010325163d -[UILayoutContainerView layoutSubviews] + 248
    23  UIKit                               0x0000000102f9911c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
    24  QuartzCore                          0x000000010146f36a -[CALayer layoutSublayers] + 146
    25  QuartzCore                          0x0000000101463bd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    26  QuartzCore                          0x0000000101463a4e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    27  QuartzCore                          0x00000001014581d5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
    28  QuartzCore                          0x00000001014859f0 _ZN2CA11Transaction6commitEv + 508
    29  UIKit                               0x0000000102f1253a _afterCACommitHandler + 174
    30  CoreFoundation                      0x0000000102a669d7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    31  CoreFoundation                      0x0000000102a66947 __CFRunLoopDoObservers + 391
    32  CoreFoundation                      0x0000000102a5c59b __CFRunLoopRun + 1147
    33  CoreFoundation                      0x0000000102a5be98 CFRunLoopRunSpecific + 488
    34  GraphicsServices                    0x0000000106016ad2 GSEventRunModal + 161
    35  UIKit                               0x0000000102ee8676 UIApplicationMain + 171
    36  My App                            0x000000010026c2cf main + 111
    37  libdyld.dylib                       0x000000010491f92d start + 1
    38  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

我应该如何找出导致问题的约束条件?我有几十个。我添加了 _NSLayoutConstraintNumberExceedsLimit() 断点,这让我在这一行停止:

NSArray *constraintAircraftV = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[xLabelsCV(==lblCvHeight)]-spacing-[timePeriodCV(==timePeriodCvHeight)]-spacing-[aircraftCV(==aircraftCvHeight)]" options:0 metrics:metrics views:views];

不过,我应该如何解决问题所在?代码没有改变,但它只是在 iOS9 更新后停止工作。

最佳答案

这是一个新的 iOS 9 问题。 替换:

[self addConstraint:[NSLayoutConstraint constraintWithItem:self.skipButton attribute:NSLayoutAttributeTrailling relatedBy:NSLayoutRelationEqual toItem:self **attribute:NSLayoutAttributeRight** multiplier:XXX constant:XXX]];

使得两个属性相同:

[self addConstraint:[NSLayoutConstraint constraintWithItem:self.skipButton attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:XXX constant:XXX]];

attribute:NSLayoutAttributeXXXX 的两种情况必须相同。

关于ios - 跟踪 NSLayoutConstraint 崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32651837/

相关文章:

ios - 在整个应用程序中完全禁用向后滑动手势

ios - Air for iOS 中是否有使用 "GPU mode"作为渲染方法的快速渲染游戏库?

objective-c - 如何在不子类化的情况下将成员变量和方法添加到内置类中

objective-c - 关联引用是如何实现的?

c - WaitForMultipleObjects 堆栈

ios - 分段控件索引更改 Swift 时取消查询

ios - 在 Swift 中测试 NSString 是否为数字的扩展

ios - Bing map 给我错误消息

c - 如果我重复运行这个程序,为什么在 seg-fault 之前打印的最后一个数字会有所不同?

c++ - 中缀到后缀 - 删除括号