【问题标题】:How to tell the tableviewcell class label name in visual format constraints?如何在视觉格式约束中告诉 tableviewcell 类标签名称?
【发布时间】:2015-12-14 10:59:41
【问题描述】:

这是我下面给出的代码:

 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-| 
          ^'

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

【问题讨论】:

  • 您的标签的属性名称是什么?是lblname吗?
  • @AndréSlotta property (nonatomic ,retain) UILabel *lblname;

标签: ios objective-c constraints


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

【讨论】:

  • super :) 现在我明白了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-10
  • 1970-01-01
  • 2022-01-14
相关资源
最近更新 更多