suchen

Heim  >  Fragen und Antworten  >  Hauptteil

objective-c - NSDictionary中的莫名错误


// NSDictionary * viewsDictionary = NSDictionaryOfVariableBindings(self.segmentControl); NSDictionary * viewsDictionary = [[NSDictionary alloc]initWithObjectsAndKeys:self.segmentControl ,@"segmentControl", nil]; [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[segmentControl]" options:0 metrics:nil views:viewsDictionary]]; // 第一句显示错误,运行不通过,显示不合法的key,原因如下: // terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse constraint format: segmentControl is not a key in the views dictionary.

我想知道,为什么第一句不对,而第二句对的。

PHP中文网PHP中文网2768 Tage vor567

Antworte allen(1)Ich werde antworten

  • 伊谢尔伦

    伊谢尔伦2017-04-22 09:02:26

    NSDictionary * viewsDictionary = @{@"segmentControl":self.segmentControl};
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[segmentControl]" options:0 metrics:nil views:viewsDictionary]];
    

    因为views中的字典是解释-[segmentControl]是哪个视图

    你的命名有严重的错误,[self.view addConstraints View上面添加控制器进行约束???

    Antwort
    0
  • StornierenAntwort