Ios 将子视图的NSLayoutConstraints设置为父视图

Ios 将子视图的NSLayoutConstraints设置为父视图,ios,nslayoutconstraint,Ios,Nslayoutconstraint,在UITableViewCell子类中,我向backgroundView添加了一个子视图: -(void)method { [self.backgroundView addSubview:self.backView]; [self setConstraintsForBackView]; } -(UIView*)backView { if (!_backView) { _backView = [[UIView alloc] initWithFrame:CG

在UITableViewCell子类中,我向backgroundView添加了一个子视图:

-(void)method {
    [self.backgroundView addSubview:self.backView];
    [self setConstraintsForBackView];
}

-(UIView*)backView {
    if (!_backView) {
        _backView = [[UIView alloc] initWithFrame:CGRectZero];
    }
    return _backView;
}
我正在尝试使
背景视图
背景视图
相匹配。我认为使用NSLayoutConstraints是最好的方法,但是
后视图总是显示原始的44点单元格高度,而不是我为每个单元格设置的实际高度。这是我的NSLayoutConstraints的代码

-(void)setConstraintsForBackView {
    [self.backView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|"
                                                                          options:0
                                                                          metrics:nil
                                                                            views:@{@"view": self.backView}]];
}
我看到以下错误:

”无法在视图上安装约束。约束是否引用了视图子树之外的内容?那是违法的。约束:视图:'

我还尝试了
@“V:|-0-[view]-0-|”
,但没有任何运气


诚然,我对NSLayoutConstraints没有太多的经验,但玩弄各种视觉格式不会产生任何结果。

您需要将约束添加到
self.backgroundView
而不是
self.backView

第一个:
self.backView.translatesAutoresizingMaskIntoConstraints=否

ie:
[self.backgroundView addConstraints:[nsLayoutConstraintsWithVisualFormat:@“V:|[view]|”
选项:0
指标:零

视图:@{@“视图”:self.backView}]]

啊,谢谢!尽管我看到了以下错误:
(“”,“”,“”,“”,“”)将尝试通过打破约束来恢复
有什么想法吗?我无法粘贴整个错误,更详细地描述了它