尝试设置布局约束的宽度和高度,我收到以下错误:
"由于未捕获的异常终止应用程序' NSInternalInconsistencyException',原因:' NSDictionaryOfVariableBindings失败,因为其中一个值为nil,或者调用宏的方式有问题。无法为键" infoButton"分配值nil。按键:( infoButton"
[holderView addSubview:infoButton];
// width constraint
[holderView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[infoButton(==44)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(infoButton)]];
// height constraint
[holderView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[infoButton(==44)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(infoButton)]];
更新:
仍然没有工作,当我的断点仍然没有?
[holderView addSubview:infoButton];
holderView.userInteractionEnabled = YES;
id views = @{@"infoButton": infoButton};
[holderView addSubview:infoButton];
// width constraint
[holderView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[infoButton(==44)]" options:0 metrics:nil views:views]];
// height constraint
[holderView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[infoButton(==44)]" options:0 metrics:nil views:views]];
答案 0 :(得分:2)
infoButton instance is nil
。