Objective c 苹果';s草图源代码NSArrayController绑定

Objective c 苹果';s草图源代码NSArrayController绑定,objective-c,cocoa-bindings,Objective C,Cocoa Bindings,多年来,我一直在为他们的Sketch应用程序编写苹果的源代码:developer.Apple.com/samplecode。他们正在将NSArrayController绑定到NSDocument中的数组 在NSWindowController的NSView中执行此操作时: [mutableGraphics insertObject:_creatingGraphic atIndex:0]; 它在NSC文档中调用此代码: - (void)insertGraphics:(NSArray *)grap

多年来,我一直在为他们的Sketch应用程序编写苹果的源代码:developer.Apple.com/samplecode。他们正在将NSArrayController绑定到NSDocument中的数组

在NSWindowController的NSView中执行此操作时:

[mutableGraphics insertObject:_creatingGraphic atIndex:0];
它在NSC文档中调用此代码:

- (void)insertGraphics:(NSArray *)graphics atIndexes:(NSIndexSet *)indexes {
我的问题是如何做到这一点?我希望能够通过编程实现这一点,这里似乎有某种魔力

我像这样绑定我的NSArrayController:

[_componentsController bind:NSContentArrayBinding toObject:self withKeyPath:@"document.components" options:NULL];
但我不知道它如何调用自定义方法

再过几天,我的头发就不见了,欢迎你给我任何建议

谢谢


克里斯,我想我已经弄明白了。NSDocument类需要与KVC兼容,因此我需要以下方法:

- (NSArray *)components {
- (void)insertComponents:(NSArray *)components atIndexes:(NSIndexSet *)indexes
- (void)removeComponentsAtIndexes:(NSIndexSet *)indexes