简体   繁体   English

iOS:addConstraints:崩溃的应用程序

[英]iOS: addConstraints: crashing app

Problem 问题

I can't seem to adopt Auto Layout into my existing project. 我似乎无法将Auto Layout应用到我现有的项目中。

Details 细节

I was having the same issue before as this question presentViewController: crash on iOS <6 (AutoLayout) but none of the provided answers were a solution for me: I'm using all storyboard views with no xibs. 之前我遇到了同样的问题,因为这个问题presentViewController:在iOS <6(AutoLayout)上崩溃但是没有提供的答案对我来说是一个解决方案:我正在使用没有xib的所有故事板视图。 My 'Use Auto Layout' setting is already turned off and I am using nothing but iOS 6. 我的“使用自动布局”设置已经关闭,我只使用iOS 6。

My view controller was initially crashing, so I set the constraints to be added with a delay and now my app crashes during any addConstraints: call. 我的视图控制器最初崩溃,所以我设置了延迟添加的约束,现在我的应用程序在任何addConstraints: call期间崩溃。 Worst part is that it won't tell me why. 最糟糕的是它不会告诉我原因。

Code

I will link my code, but its pretty straight forward. 我将链接我的代码,但它很直接。

-(void)addAllConstraints
{
    NSDictionary * views = NSDictionaryOfVariableBindings(_memoryImage, _peopleView, _contentHolder, _commentsTableView);
    NSArray * constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[_memoryImage]-50-[_peopleView]-0-[_contentHolder]-0-[_commentsTableView]" options:0 metrics:nil views:views];
    NSLog(@"Views %@, Constraints %@", views, constraints);
    [_peopleView addConstraints:constraints];
    [_memoryImage addConstraints:constraints];
    [_contentHolder addConstraints:constraints];
   [_commentsTableView addConstraints:constraints];
}

App crashes on _peopleView 's call to addConstraints. 应用程序在_peopleView调用addConstraints时崩溃。 Both the views and the NSLayoutConstraints are successfully created. 视图和NSLayoutConstraints都已成功创建。

Any ideas? 有任何想法吗? Thank you, Happy Holidays. 谢谢,节日快乐。

EDIT: 编辑:

Adding Crash logs to show that nothing useful is showing: 添加崩溃日志以显示没有任何有用的信息显示:

2012-12-25 10:40:13.936 -----[4955:907] Views {
"_commentsTableView" = "<UITableView: 0x1eb6be00; frame = (0 372; 320 100); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1e51ce00>; layer = <CALayer: 0x1e51cee0>; contentOffset: {0, 0}>";
"_contentHolder" = "<UIView: 0x1e5c6590; frame = (0 270; 320 112); layer = <CALayer: 0x1e5c27f0>>";
"_memoryImage" = "<UIButton: 0x1e5c4aa0; frame = (0 0; 320 280); opaque = NO; layer = <CALayer: 0x1e5c4b60>>";
"_peopleView" = "<UIView: 0x1f0ceea0; frame = (0 230; 320 50); layer = <CALayer: 0x1f0cf790>>";

Constraints (
"NSLayoutConstraint:0x1e51a880 V:[UIButton:0x1e5c4aa0]-(50)-[UIView:0x1f0ceea0]",
"NSLayoutConstraint:0x1e5ba4e0 V:[UIView:0x1f0ceea0]-(0)-[UIView:0x1e5c6590]",
"NSLayoutConstraint:0x1e51b860 V:[UIView:0x1e5c6590]-(0)-[UITableView:0x1eb6be00]"
)


}  
   (lldb) 

Constraints are supposed to be added to the view that is the superview of the subviews. 应该将约束添加到作为子视图的超级视图的视图中。 So, if these objects are in your main view, then you should have (and none of the other addConstraints: lines): 因此,如果这些对象在您的主视图中,那么您应该(并且没有其他addConstraints:行):

[self.view addConstraints:constraints];

Also, your dictionary, views, should be nil terminated (I don't know whether this is necessary or not. I've noticed in an Apple example that they didn't do this, but the function definition shows it with the nil). 此外,你的字典,视图,应该是零终止(我不知道这是否是必要的。我已经注意到在Apple示例中他们没有这样做,但函数定义显示为nil) 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM