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

// 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级讲师

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

Because the dictionary in views is the explanation - which view [segmentControl] is

There is a serious mistake in your naming. [self.view addConstraints Add controllers to View for constraints? ? ?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template