IOS6界面构建器自动布局:CRASH无法在视图上安装约束

时间:2012-09-17 07:33:23

标签: iphone sdk ios6

当我尝试通过自动布局添加所有视图时,它会显示以下消息:

CRASH Unable to install constraint on view. 
Does the constraint reference something from outside the subtree of the view?  
That's illegal. 
constraint:<NSLayoutConstraint:0x756b510 UIPickerView:0x756f220.top == 
LoginView:0x75e9d30.top + 106> view:<LoginView: 0x75e9d30; 
frame = (0 15; 320 430); autoresize = RM+BM; layer = <CALayer: 0x75e9dc0>>

有人有想法吗?

2 个答案:

答案 0 :(得分:0)

我在选择器视图中确实遇到了同样的问题。点击输入字段打开了选择器视图,然后我在选择器视图上选择了一些并关闭它。当转到另一个视图,然后再回到pickerview时,我收到了提到的错误。我通过关闭autolayout来解决它。这可以在文件检查器上完成,只需取消选中autolayout。

答案 1 :(得分:-1)

快速提示: 您必须为一个View Controller创建3个XIB

  1. YourViewController.xib,
  2. YourViewController-568.xib,
  3. YourViewController〜ipad.xib
  4. 并在每个YourViewController.m中添加以下代码 然后它将为不同的用户设备加载不同的视图

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
       // if(nibNameOrNil == nil){
            nibNameOrNil = @"YourViewController";
    
            if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
                if([UIScreen mainScreen].bounds.size.height > 480){
    
                    nibNameOrNil = @"YourViewController-568";
                    // iphone5+
                }else{
                    // older than iphone5
                }
            }
       // }
    
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self){
    
        }
        return self;
    }