gpt4 book ai didi

ios - NSLayoutConstraint 抛出异常 "is not a key in the views dictionary"

转载 作者:行者123 更新时间:2023-11-29 02:24:05 25 4
gpt4 key购买 nike

我正在尝试以编程方式使用自动布局并面临一些问题。我的代码很简单。我有一个 View ,我正在尝试使用 NSLayoutConstraint 添加标签,如下所示

 UILabel* downloadLabel = [[UILabel alloc] init];
[self.leftView addSubview:downloadLabel];
downloadLabel.translatesAutoresizingMaskIntoConstraints = NO;
[downloadLabel setBackgroundColor:[UIColor redColor]];

NSDictionary *downloadlabelDict = NSDictionaryOfVariableBindings(downloadLabel);
NSArray *downloadLabelConstraint_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[dowloadLabel(40)]"
options:0
metrics:nil
views:downloadlabelDict];
NSArray *downloadLabelConstraint_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[dowloadLabel(200)]"
options:0
metrics:nil
views:downloadlabelDict];


[downloadLabel addConstraints:downloadLabelConstraint_H];
[downloadLabel addConstraints:downloadLabelConstraint_V];

当我运行应用程序时,它在尝试创建第一个 NSLayoutConstraint 时抛出异常。

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse constraint format: 
dowloadLabel is not a key in the views dictionary.V:[dowloadLabel(40)]

最佳答案

也许您在构建约束的两行中指的是 downloadLabel 而不是 dowloadLabel

关于ios - NSLayoutConstraint 抛出异常 "is not a key in the views dictionary",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27757249/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com