Linux Interface Builder NSStaticText 值需要在每次对话框中发生任何变化时更新

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3677082/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 23:13:56  来源:igfitidea点击:

Interface Builder NSStaticText value needs to be updated every time anything changes in dialog

objective-ccocoamacosinterface-builder

提问by Tom Andersen

I have a modal dialog thats building a string. The string is shown to the user, and the user presses checkboxes, radio boxes, etc to build the string. The string exists nowhere - I build it for display in -()builtString; from the configuration of the self.valuesDict.

我有一个正在构建字符串的模式对话框。字符串显示给用户,用户按下复选框、单选框等来构建字符串。该字符串无处不在 - 我构建它以在 -()builtString; 中显示;来自 self.valuesDict 的配置。

I can easily wire up the checkboxes via bindings in IB: for example to the files owner (the controller) with self.valuesDict.checkbox1

我可以通过 IB 中的绑定轻松连接复选框:例如使用 self.valuesDict.checkbox1 连接到文件所有者(控制器)

Also I bound the display of the string to "self.builtString".

我还将字符串的显示绑定到“self.builtString”。

But every time any checkbox changes, I want to redisplay the string that's shown to the user.

但是每次任何复选框更改时,我都想重新显示向用户显示的字符串。

If I abandon bindings, then I think I can use the [self willChangeValueForKey:@"builtString"], for each checkbox, etc, I think, but that is some messy looking code by the time I deal with them all.

如果我放弃绑定,那么我想我可以对每个复选框使用 [self willChangeValueForKey:@"builtString"],我认为,但是当我处理它们时,这是一些看起来很混乱的代码。

So how do you tell a nstextfield in IB to update every time say self.valuesDict changes?

那么你如何告诉 IB 中的 nstextfield 每次说 self.valuesDict 更改时更新?

Thanks for any comments/suggestions.

感谢您提出任何意见/建议。

--Tom

——汤姆

采纳答案by Sven

You can specify dependencies between bindings. Just write a class method +(NSSet*) keyPathsForValuesAffectingBuiltStringthat returns a set with all key paths of properties builtStringdepends on. Then things bound to your string will also be updated when one of the other properties is changed. For more details and step-by-step instructions you can look at this article.

您可以指定绑定之间的依赖关系。只需编写一个类方法+(NSSet*) keyPathsForValuesAffectingBuiltString,该方法返回一个集合,其中包含所builtString依赖的属性的所有关键路径。然后,当其他属性之一更改时,绑定到您的字符串的内容也将更新。有关更多详细信息和分步说明,您可以查看这篇文章