objective-c - NSDictionary中的莫名错误
PHP中文网
PHP中文网 2017-04-22 09:00:26
0
1
559

// 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中文网

认证0级讲师

Antworte allen(1)
伊谢尔伦
NSDictionary * viewsDictionary = @{@"segmentControl":self.segmentControl};
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[segmentControl]" options:0 metrics:nil views:viewsDictionary]];

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

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

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage