如何使用标识符将 NSLayoutConstraint 访问到 tableviewcell 中?

how to access NSLayoutConstraint into tableviewcell with identifier to it?

我在我的项目中使用了 autolayout,但有一种情况让我卡住了。我已经用 TableviewCell 的 Custom XIB 完成了,但我想用 Tableview 的默认原型单元格来完成它。我的设计如下

现在在我的设计中,我 select constraint 顶部到按钮并给出如下标识符

Tableview 原型 cell 中,我不能说出来。那么我如何使用标识符访问 NSLayoutConstraint。我通过网络搜索但没有找到

请帮帮我
谢谢

希望这对您有所帮助。

    NSArray *constraints = [myView constraints]; // Here myView is a reference to the required UI component 
    int count = [constraints count];
    int index = 0;
    BOOL found = NO;

    while (!found && index < count) {
        NSLayoutConstraint *constraint = constraints[index];
        if ( [constraint.identifier isEqualToString:@"topconstraint"] ) {
            //save the reference to constraint
            constraint.constant = yourValue;
            found = YES;
        }
        index++;
    }

同样使用Predicate,可以过滤掉:

constraints.filter{ [=11=].identifier == "MyIdentifierText" }.first { }