ios - 无法同时满足约束,将尝试通过打破约束来恢复

以下是我在调试区收到的错误消息。它运行良好,除了我收到此错误之外没有任何问题。这会阻止苹果接受该应用程序吗?我该如何解决?

2012-07-26 01:58:18.621 Rolo[33597:11303] 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:0x887d630 h=--& v=--& V:[UIButtonLabel:0x886ed80(19)]>",
    "<NSAutoresizingMaskLayoutConstraint:0x887d5f0 h=--& v=--& UIButtonLabel:0x886ed80.midY == + 37.5>",
    "<NSAutoresizingMaskLayoutConstraint:0x887b4b0 h=--& v=--& V:[UIButtonLabel:0x72bb9b0(19)]>",
    "<NSAutoresizingMaskLayoutConstraint:0x887b470 h=--& v=--& UIButtonLabel:0x72bb9b0.midY == - 0.5>",
    "<NSLayoutConstraint:0x72bf860 V:[UILabel:0x72bf7c0(17)]>",
    "<NSLayoutConstraint:0x72c2430 UILabel:0x72bfad0.top == UILabel:0x72bf7c0.top>",
    "<NSLayoutConstraint:0x72c2370 UILabel:0x72c0270.top == UILabel:0x72bfad0.top>",
    "<NSLayoutConstraint:0x72c22b0 V:[UILabel:0x72bf7c0]-(NSSpace(8))-[UIButton:0x886efe0]>",
    "<NSLayoutConstraint:0x72c15b0 V:[UILabel:0x72c0270]-(NSSpace(8))-[UIRoundedRectButton:0x72bbc10]>",
    "<NSLayoutConstraint:0x72c1570 UIRoundedRectButton:0x72bbc10.baseline == UIRoundedRectButton:0x7571170.baseline>",
    "<NSLayoutConstraint:0x72c21f0 UIRoundedRectButton:0x7571170.top == UIButton:0x886efe0.top>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x72bf860 V:[UILabel:0x72bf7c0(17)]>

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.

最佳答案

我建议调试并找出哪个约束是“你不想要的”。假设您有以下问题:

问题始终是如何找到以下约束和 View 。

有两种解决方法:

  1. DEBUG VIEW HIERARCHY (不推荐这种方式)

由于您知道在哪里可以找到意外约束 (PBOUserWorkDayHeaderView),因此有一种方法可以很好地做到这一点。让我们在红色矩形中找到 UIViewNSLayoutConstraint。因为我们知道他们的内存中的id,所以这很容易。

  • 使用Debug View Hierarchy停止应用:

  • 找到合适的 UIView:

  • 接下来就是找到我们关心的NSLayoutConstraint:

如您所见,内存指针是相同的。所以我们知道现在发生了什么。此外,您可以在 View 层次结构中找到 NSLayoutConstraint。既然是在 View 中被选中的,那么在 Navigator 中也被选中了。

如果您需要,您也可以使用地址指针在控制台上打印:

(lldb) po 0x17dce920
<UIView: 0x17dce920; frame = (10 30; 300 24.5); autoresize = RM+BM; layer = <CALayer: 0x17dce9b0>>

您可以对调试器指向您的每个约束执行相同的操作:-) 现在您决定如何处理它。

  1. 更好地打印它 (我真的推荐这种方式,这是 Xcode 7 的)

    • 为 View 中的每个约束设置唯一标识符:

  • NSLayoutConstraint 创建简单的扩展:

SWIFT:

extension NSLayoutConstraint {

    override public var description: String {
        let id = identifier ?? ""
        return "id: \(id), constant: \(constant)" //you may print whatever you want here
    }
}

objective-C

@interface NSLayoutConstraint (Description)

@end

@implementation NSLayoutConstraint (Description)

-(NSString *)description {
    return [NSString stringWithFormat:@"id: %@, constant: %f", self.identifier, self.constant];
}

@end
  • 再次构建它,现在您可以获得更易读的输出:

  • 获得id后,您可以在Find Navigator中轻按它:

  • 并快速找到它:

如何简单地解决这种情况?

  • 尝试将 priority 更改为 999 以防止约束失效。

https://stackoverflow.com/questions/11664115/

相关文章:

ios - 使用 glob 获取目录中的文件列表

ios - 以编程方式在 UIStackView 中添加 View

iphone - 错误 : The service is invalid

objective-c - 为什么在 C 中将 1,000,000,000 写为 1000*1000

ios - 如何使 UIButton 文本对齐中心?使用 IB

ios - 如何在 UILabel 中嵌入小图标

iphone - 什么是使 iOS 应用程序崩溃的可靠方法?

iphone - 以编程方式选择 tableview 行

ios - Objective-C 和 Swift URL 编码

objective-c - 关于iOS5 SDK中自动引用计数的一些问题