ios - 解除 View Controller 时发生奇怪的崩溃,归咎于自动布局?

标签 ios autolayout

我遇到了一次非常奇怪的崩溃,这是回溯。

* thread #1: tid = 0x2403, 0x3379516c CoreFoundation`CFHash + 8, stop reason = EXC_BREAKPOINT (code=EXC_ARM_BREAKPOINT, subcode=0xdefe)
    frame #0: 0x3379516c CoreFoundation`CFHash + 8
    frame #1: 0x33797a9c CoreFoundation`CFBasicHashRemoveValue + 1408
    frame #2: 0x337974ee CoreFoundation`CFDictionaryRemoveValue + 166
    frame #3: 0x3420988e Foundation`-[NSISEngine removeConstraintWithMarker:] + 562
    frame #4: 0x34211dbe Foundation`-[NSLayoutConstraint _removeFromEngine:] + 230
    frame #5: 0x35a954ec UIKit`-[UIView(UIConstraintBasedLayout) _layoutEngine_willRemoveLayoutConstraint:] + 44
    frame #6: 0x358488fc UIKit`__48-[UIScrollView _setAutomaticContentConstraints:]_block_invoke_0 + 148
    frame #7: 0x34208882 Foundation`-[NSISEngine withAutomaticOptimizationDisabled:] + 166
    frame #8: 0x35848838 UIKit`-[UIScrollView _setAutomaticContentConstraints:] + 116
    frame #9: 0x35848e6c UIKit`-[UIScrollView _rememberDependentConstraint:] + 112
    frame #10: 0x35a9e3ae UIKit`___updateViewDependenciesForConstraint_block_invoke_0 + 30
    frame #11: 0x35a954ba UIKit`_updateViewDependenciesForConstraint + 202
    frame #12: 0x35a953da UIKit`-[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 154
    frame #13: 0x35a95534 UIKit`-[UIView(UIConstraintBasedLayout) _tryToAddConstraintWithoutUpdatingConstraintsArray:roundingAdjustment:mutuallyExclusiveConstraints:] + 36
    frame #14: 0x3567c2e0 UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] + 376
    frame #15: 0x356d34fe UIKit`-[UIScrollView _didMoveFromWindow:toWindow:] + 50
    frame #16: 0x3567c5c6 UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] + 1118
    frame #17: 0x35676e52 UIKit`-[UIView(Hierarchy) _postMovedFromSuperview:] + 138
    frame #18: 0x3565e7dc UIKit`-[UIView(Internal) _addSubview:positioned:relativeTo:] + 1300
    frame #19: 0x3565e2c2 UIKit`-[UIView(Hierarchy) addSubview:] + 30
    frame #20: 0x356f68e8 UIKit`-[UITransitionView transition:fromView:toView:removeFromView:] + 972
    frame #21: 0x35937618 UIKit`__91-[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:]_block_invoke_0238 + 388
    frame #22: 0x357499b8 UIKit`-[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 4824
    frame #23: 0x357b9814 UIKit`-[UIViewController _dismissViewControllerWithTransition:from:completion:] + 1708
    frame #24: 0x357057c4 UIKit`-[UIViewController dismissViewControllerWithTransition:completion:] + 912
    frame #25: 0x000ccd40 Capture`-[INFTagSearchViewController cancelButtonTouched:](self=0x1f09ed50, _cmd=0x001b9d5f, sender=0x1e0265c0) + 76 at INFTagSearchViewController.m:48
    frame #26: 0x357470c4 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 72
    frame #27: 0x35747076 UIKit`-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 30
    frame #28: 0x35747054 UIKit`-[UIControl sendAction:to:forEvent:] + 44
    frame #29: 0x3574690a UIKit`-[UIControl(Internal) _sendActionsForEvents:withEvent:] + 502
    frame #30: 0x35746e00 UIKit`-[UIControl touchesEnded:withEvent:] + 488
    frame #31: 0x3566f5f0 UIKit`-[UIWindow _sendTouchesForEvent:] + 524
    frame #32: 0x3565c800 UIKit`-[UIApplication sendEvent:] + 380
    frame #33: 0x3565c11a UIKit`_UIApplicationHandleEvent + 6154
    frame #34: 0x373655a2 GraphicsServices`_PurpleEventCallback + 590
    frame #35: 0x373651d2 GraphicsServices`PurpleEventCallback + 34
    frame #36: 0x33829172 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
    frame #37: 0x33829116 CoreFoundation`__CFRunLoopDoSource1 + 138
    frame #38: 0x33827f98 CoreFoundation`__CFRunLoopRun + 1384
    frame #39: 0x3379aebc CoreFoundation`CFRunLoopRunSpecific + 356
    frame #40: 0x3379ad48 CoreFoundation`CFRunLoopRunInMode + 104
    frame #41: 0x373642ea GraphicsServices`GSEventRunModal + 74
    frame #42: 0x356b0300 UIKit`UIApplicationMain + 1120
    frame #43: 0x000a297c Capture`main(argc=1, argv=0x2fd60cfc) + 116 at main.m:16
    frame #44: 0x3bb2bb20 libdyld.dylib`start + 4

您会注意到第 25 帧是我的代码进行的唯一调用,它看起来像 cancelButtonTouched

- (IBAction)cancelButtonTouched:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

我不知道发生了什么,我以前从未遇到过这样的问题,根据系统调用,它似乎是一个自动布局问题。我验证了在崩溃发生之前在呈现 View Controller 上调用了 viewWillApper,因此我假设它是在呈现 View 布局期间发出的。

关于如何将此问题缩小到特定布局约束的任何想法?或者有什么其他想法?

这在某些设备上是可重现的,而在其他设备上则很少发生。所以它是间歇性的。

更新

断点截图

enter image description here

更新 2

所以这绝对是一个问题,解散到 presentingViewController,解散两个深度([self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil])工作正常,但显然不是想要的结果,我只想回到1级。这进一步使我相信存在“重新布局” View 的问题。

最佳答案

我似乎记得这样的事情,虽然不确定它是否完全相同。在我的例子中,它是由调用 addSubview: (或 insertSubview:...) 引起的,其中的 View 已经是一个 subview 。虽然通常我认为 UIView 会处理这个问题,但使用自动布局似乎可以将某些关联信息添加到其他地方两次,并且在尝试清除该关联信息时可能会发生崩溃。在我的例子中,解决方案是确保我只添加一次 subview ,并且这次崩溃(或者我的类似崩溃)消失了。

关于ios - 解除 View Controller 时发生奇怪的崩溃,归咎于自动布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15627419/

相关文章:

ios - UIScrollView 动态高度内容(自动布局)未填满整个空间

ios - UITableViewCell IBAction 在 iOS 7 中不起作用

ios - iOS 中的 JSON 响应中出现不需要的 XML header 字符串

iphone - 只需在我的应用程序中进行控制即可发出 sigabrt 信号

ios - 为什么 UILayoutGuide 在 subviews 数组中的顺序不一致?

ios - 如何为等间距按钮添加 Storyboard约束

iphone - 使用 xcode 4.2 调试代码时出现问题

c# - 如何使用 Monotouch 对话框显示 UIPickerView?

ios - 在 UITableView 中使用自动布局进行动态单元格布局和可变行高

iOS 自动布局坐标和以编程方式绘制 View