Joh*_*Cox 140 debugging objective-c ios nslayoutconstraint
以下是我在调试区域收到的错误消息.它运行正常,没有任何错误,除了我收到此错误.这会阻止苹果接受应用吗?我如何解决它?
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.
Run Code Online (Sandbox Code Playgroud)
Bar*_*zyk 257
我建议调试并找到哪个约束是"你不想要的".假设您有以下问题:

问题始终是如何找到以下约束和视图.
有两种解决方法:
既然您知道在哪里可以找到意外的约束(PBOUserWorkDayHeaderView),那么有一种方法可以很好地完成这项工作.让我们找到UIView并NSLayoutConstraint以红色矩形.因为我们知道他们在内存中的id很容易.



如您所见,内存指针是相同的.所以我们知道现在发生了什么.此外,您可以NSLayoutConstraint在视图层次结构中找到 由于它是在View中选择的,因此它也在Navigator中选择.

如果需要,您也可以使用地址指针在控制台上打印:
(lldb) po 0x17dce920
<UIView: 0x17dce920; frame = (10 30; 300 24.5); autoresize = RM+BM; layer = <CALayer: 0x17dce9b0>>
Run Code Online (Sandbox Code Playgroud)
您可以对调试器指向您的每个约束执行相同操作:-)现在您决定如何处理此问题.
印刷它更好 (我真的推荐这种方式,这是Xcode 7)
NSLayoutConstraint:SWIFT:
extension NSLayoutConstraint {
override public var description: String {
let id = identifier ?? ""
return "id: \(id), constant: \(constant)" //you may print whatever you want here
}
}
Run Code Online (Sandbox Code Playgroud)
Objective-C的
@interface NSLayoutConstraint (Description)
@end
@implementation NSLayoutConstraint (Description)
-(NSString *)description {
return [NSString stringWithFormat:@"id: %@, constant: %f", self.identifier, self.constant];
}
@end
Run Code Online (Sandbox Code Playgroud)
id它,你可以在Find Navigator中轻松点击它:怎么简单修复那种情况?
999断开的约束.Dav*_*ong 108
你遇到的问题是NSAutoresizingMaskLayoutConstraints不应该在那里.这是弹簧和支柱的旧系统.要摆脱它,请在您想要约束的每个视图上运行此方法:
[view setTranslatesAutoresizingMaskIntoConstraints:NO];
Run Code Online (Sandbox Code Playgroud)
ped*_*uan 28
请注意,不要在同一方向和类型中使用多个约束.
例如: 尾随的垂直约束= 15,另一个> = 10.
有时,Xcode会创建一些您不会注意到的约束.你必须摆脱冗余约束,日志警告肯定会消失.

另外,您可以直接从日志中读取并检测某些原因:
NSLayoutConstraint:0xa338390 V:| - (15) - [UILabel:0xa331260](名称:'|':UILabel:0xa330270)>
我们可以将其视为UILabel约束中的问题,它导致垂直约束为15pt长.
NSLayoutConstraint:0x859ab20 H :-(13) - | [UIView:0x85a8fb0] ...
这将是尾随水平约束等.
我抛出了相当多的异常,我发现解决它们的最快和最简单的方法是在例外中找到唯一值,然后我在storyboard源代码中搜索.这有助于我找到导致问题的实际视图和约束(我在所有视图上使用有意义的userLabel,这使得跟踪约束和视图变得更加容易)...
因此,使用上述例外情况,我会将故事板作为xcode(或其他编辑器)中的"源代码"打开,并寻找我能找到的东西......
<NSLayoutConstraint:0x72bf860 V:[UILabel:0x72bf7c0(17)]>
Run Code Online (Sandbox Code Playgroud)
..这看起来像UILabel上的垂直(V)约束,值为(17).
通过例外我也发现
<NSLayoutConstraint:0x72c22b0 V:[UILabel:0x72bf7c0]-(NSSpace(8))-[UIButton:0x886efe0]>
Run Code Online (Sandbox Code Playgroud)
看起来像UILabel(0x72bf7c0)接近UIButton(0x886efe0),有一些垂直间距(8).
希望这足以让我在故事板源代码中找到特定的视图(可能通过最初搜索文本"17"),或者至少是一些可能的候选者.从那里我应该能够真正弄清楚它们在故事板中的哪些视图,这将使识别问题变得容易得多(寻找"重复"固定或固定与大小限制冲突).
我很难搞清楚导致此错误的约束条件.这是一种更简单的方法.
我正在使用Xcode 6.1.1
这是我的经验和解决方案。我没有碰代码
快速使用此代码
view.translatesAutoresizingMaskIntoConstraints = false
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
126476 次 |
| 最近记录: |