我对自定义视图的绑定属性有疑问。该属性绑定到核心数据实体的 NSArrayController。
这是问题所在:
在我看来,我画了几个矩形。这些矩形的位置保存在核心数据中的实体中(作为 NSValue 包装的 NSRects)。矩形是可拖动的,当我拖动一个矩形时,我希望实体更新到新位置。但我不知道如何将 arrayController 绑定回视图。
以下是一切的连接方式:
我有一个带有视图和arrayController 插座的windowController。
arrayController 绑定到 windowController 的 managedObjectContext ,因此绑定到我的核心数据模型。(该绑定和与实体的绑定是在 Interface Builder 中建立的)
视图通过 ivar“rectangleValuesArray”绑定到 arrayController
最后一个绑定是在 windowController 中建立的,使用:
[connectionsView bind:@"rectangleValuesArray"
toObject:elementsArrayController
withKeyPath:@"arrangedObjects.rectangleValue"
options:nil];
到目前为止有效。
现在我尝试在另一个方向建立绑定:
[elementsArrayController bind:@"arrangedObjects.rectangleValue"
toObject:connectionsView
withKeyPath:@"rectangleValuesArray"
options:nil];
现在,当我更改 ivar 时,应该更新实体(对吗?)。但这不起作用 - 我从控制台得到:
Cocoa Bindings: Error setting value for bound property arrangedObjects.rectangleValue of object <NSArrayController: 0x200027100>[entity: Element, number of selected objects: 1]: [<NSArrayController 0x200027100> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key arrangedObjects.rectangleValue.
我在这里做错了什么?请问,有人帮忙吗?
西蒙