gpt4 book ai didi

ios - 如何在视觉格式约束中告诉 tableviewcell 类标签名称?

转载 作者:行者123 更新时间:2023-11-28 19:40:59 25 4
gpt4 key购买 nike

这是我下面给出的代码:

 NSDictionary *viewsDictionary =   NSDictionaryOfVariableBindings(cell.lblname);
NSLog(@"%@",viewsDictionary);
NSArray *constra= [NSLayoutConstraint constraintsWithVisualFormat:@"|-10-[cell.lblname]-10-|" options:NSLayoutFormatAlignAllBaseline metrics:nil views:viewsDictionary];
//Work through the array of constraints, applying each to the superview
for (int i = 0; i<constra.count; i++) {
[cell.contentView addConstraint:constra[i]];
}

这是我得到的

2015-12-14 16:23:34.846 hello[2354:102290] {
"cell.lblname" = "<UILabel: 0x7fd6a1cb7a80; frame = (0 0; 318 40); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7fd6a1cf4610>>";
}
2015-12-14 16:23:34.898 hello[2354:102290] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse constraint format:
cell is not a key in the views dictionary.
|-10-[cell.lblname]-10-|
^'

如何解决这个问题帮助我,我是视觉约束的新手....

最佳答案

NSDictionary *viewsDictionary = {@"lblname": self.lblname};
NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|-10-[lblname]-10-|" options:NSLayoutFormatAlignAllBaseline metrics:nil views:viewsDictionary];
[cell.contentView addConstraints:constraints];

关于ios - 如何在视觉格式约束中告诉 tableviewcell 类标签名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34265300/

25 4 0