将不可满足的NSLayoutConstraints的内存地址映射到UI控件

Vap*_*olf 7 iphone ipad ios lldb nslayoutconstraint

我很欣赏XCode将捕获不可解决的NSLayoutConstraints信息,并提供有关它的一些信息,但是我不知道如何获取控件/约束的内存地址并将其映射到有问题的实际控件.

我的应用程序相当大(大约20个屏幕),有些是大型UIViewControllers,其中有几个子视图控制器.一些是带有自定义单元格的UITableViews和带有自定义单元格的UICollectionViews.我有一段时间来解决这个错误的原因(在横向旋转时发生)

以下是我的控制台中的信息:

2013-05-02 11:18:53.225 Smile[7519:c07] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x16083b60 h=-&- v=-&- UIView:0xa5a1d00.width == UIWindow:0xa09eee0.width>",
    "<NSLayoutConstraint:0xa5a2180 V:[UIView:0xa59f160]-(954)-|   (Names: '|':UIView:0xa5a1d00 )>",
    "<NSLayoutConstraint:0xa5a2140 V:|-(0)-[UIView:0xa59f160]   (Names: '|':UIView:0xa5a1d00 )>",
    "<NSAutoresizingMaskLayoutConstraint:0xa593340 h=--- v=--- H:[UIWindow:0xa09eee0(768)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0xa5a2180 V:[UIView:0xa59f160]-(954)-|   (Names: '|':UIView:0xa5a1d00 )>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
Run Code Online (Sandbox Code Playgroud)

如您所见,列出了内存地址.将它们粘贴到观察窗口的搜索栏中并没有太多显示.通过线程和队列调用堆栈进行筛选,我只在此断点上获得反汇编代码(异常断点).

Mar*_* Dm 8

由于这些网站,我找到了一种解决方案:调试iOS AutoLayout问题使用调试器跳舞.感谢Xcode控制台,您可以确定问题来自哪个视图.

解决方案:

  • 步骤1:

    • 打开断点导航器(cmd + 7)
    • 单击左下方的"添加"按钮
    • 选择"添加符号断点"
    • 在哪里说'符号'输入 UIViewAlertForUnsatisfiableConstraints
  • 第2步:运行您的项目.控制台打印时Will attempt to recover by breaking constraint <NSLayoutConstraint:0x7fc82d3e18a0 H:[UIView:0x7fc82aba1210(768)]>,复制视图的内存地址(0x7fc82aba1210此处).

  • 步骤3:在控制台中使用此命令更改此视图的背景以了解它是哪一个: e (void)[0x7fc82d3e18a0 setBackgroundColor:[UIColor redColor]]

  • 第4步:继续该程序并查看更新的UI.红色背景颜色的视图是有问题的视图.

  • 步骤5:返回到您的IB并查找此视图中存在问题的约束.

  • 第3步很棒! (3认同)

Zev*_*erg 0

您可以尝试使用此处visualizeConstraints:提到的方法,看看是否可以通过这种方式找到不良约束。