0

我有以下具有几个属性的对象:

public class Test : NSObject
{
    [Export("formattedFoo")]
    public string FormattedFoo { get { return string.Format("Test {0}", Foo); } }

    [Export("foo")]
    public string Foo { get; set; }
}

在 Interface Builder 中,我有一个绑定到的文本字段foo和一个绑定到formattedFoo. 每当用户在文本字段中键入文本时,Foo属性都会按预期更新。但是,标签不会更新。

我怀疑我需要实现一些东西来传达CocoafooformattedFooCocoa 之间的依赖关系,但我不确定是什么。

在有人建议我在 IB 中使用格式化表达式之前,这并不是一个真正的选择,因为上面是现实生活场景的一个非常简单的例子。

4

1 回答 1

0

想通了,这里是相关资源:

代码需要使用以下方法进行扩展:

[Export("keyPathsForValuesAffectingFormattedFoo")]
public static NSSet GetDependenciesForFormattedFoo()
{
     return new NSSet("foo");
}

基本上,您必须有一个public static名称以“keyPathsForValuesAffecting”开头并以具有依赖关系的属性名称结尾的方法。

于 2014-07-10T22:40:02.223 回答