WillChangeValue为keypath

时间:2013-09-27 19:11:01

标签: objective-c monomac

我在一个具有属性的类中有一个类,例如Car.Engine.Name。我已经实现了KVC,并希望发送WillChangeValue作为“Engine.Name”但它似乎没有注册。另一方面,为Car.Name的“Name”发送WillChangeValue确实有效。

        Object target = _t;
        PropertyInfo info;
        for (int i = 0; i < keys.Length; i++) {
            info = target.GetType ().GetProperty (keys[i]);
            if (i == keys.Length - 1) {
                WillChangeValue (nsKeyPath);  // <--- doesn't seem to work if there is a nontrival keypath
                info.SetValue (target, nsValue.ToObject (info.PropertyType), null);
                DidChangeValue (nsKeyPath);
            } else {

                target = info.GetValue (target, null);
            }
        }

1 个答案:

答案 0 :(得分:0)

以下是答案,我需要更改顶级节点的WillChange,例如WillChangeValue(“Engine”)。在实现的代码中,WillChangeValue(keys [0])