2017-05-27 6 views
2

イントロdictionary`に重要ではありません。NSLayoutConstraint `ビューはビューが

はい、私は主題に関連する質問のすべてを見ていると、答えのどれも助けません。下のコードは私にNSInvalidArgumentExceptionの例外を投げつけていますが、私はまだ何が間違っているか見ることはできません。

質問:私は、私はおそらく試みることができるすべてのものを試してみた

。常に同じエラーメッセージでクラッシュしています。 'Unable to parse constraint format: sceneView is not a key in the views dictionary.'。ここで

は私が何をすべきかです:

-(void)commonInitで次に
- (SCNView *)sceneView { // Lazy Load 
    if (_sceneView == nil) { 
    _sceneView = [[SCNView alloc] initWithFrame:self.bounds]; 
    _sceneView.backgroundColor = [UIColor blackColor]; 
    _sceneView.scene = self.scene; // Load scene 
    _sceneView.translatesAutoresizingMaskIntoConstraints = NO; 

    } 
    return _sceneView; 
} 

、私はそれを追加します。

if ([self.sceneView isDescendantOfView:self] == NO) { 
    [self addSubview:self.sceneView]; 
    } 

    [self.sceneView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[sceneView]|" 
                     options:0 
                     metrics:nil 
                      views:NSDictionaryOfVariableBindings(self.sceneView)]]; 

その直後、それは例外で終了します。どうして?

答えて

2

自己を使用しています。オブジェクトを返すメソッドを呼び出すためのものであり、あなたが間違っているキーとして使用できるものではありません。以下の方法を使用して、クラッシュの問題を修正します:

[self.sceneView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_sceneView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_sceneView)]]; 
1

実は、NSDictionaryOfVaribaleBindingsはマクロ

_NSDictionaryOfVariableBindingsです(@ "" #VA_ARGSVA_ARGS、ゼロ)、

あなたはそれが何であるかのようになります使用変数コードでは、@ {"self.sceneView":self.sceneView}のNSDictionaryを取得するので、@ "H:| [self.sceneView] |のようなものに変更する必要があります。それを機能させる。

関連する問題