绑定到 NSTreeController SelectionIndexPaths
我想通过执行以下操作以编程方式绑定到 NSTreeController 的选择索引路径(以便我可以获取一个选择字符串并在文本视图中显示)
[activePDFView绑定:@“名称” toObject:treeController withKeyPath:@"selectionIndexPaths.nodeName" 选项:选项];
树控制器绑定到一个 NSMutableArray,其中包含具有“nodeName”属性的对象。 NSMutableArray 内的对象对于属性“nodeName”来说是符合 KVC 的,因为我已经实现了正确的访问器。
当我编译时,我收到以下消息
'[<__NSArray0 0x1001698d0>> addObserver:forKeyPath:选项:上下文:] 不支持。关键路径:nodeName'
我不太确定,但我的绑定正确吗?
谢谢。
I want to bind to a NSTreeController's selectionIndexPaths programatically by doing the following (so that I can get a string a selection and display in a text view)
[activePDFView bind:@"name"
toObject:treeController
withKeyPath:@"selectionIndexPaths.nodeName"
options:options];
The tree controller is bound to a NSMutableArray that contains objects with the "nodeName" property. The object inside the NSMutableArray is KVC compliant for the property "nodeName" since I've implemented the proper accessors.
When I compile, I get the following message
'[<__NSArray0 0x1001698d0>
addObserver:forKeyPath:options:context:]
is not supported. Key path: nodeName'
I am not quite sure but is my binding correct?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您想要绑定的不是
selectionIndexPaths
,而是selection
绑定。selectionIndexPaths
绑定将返回一个NSIndexPath
对象数组,通常仅在将大纲/浏览器视图的选择绑定到树控制器时使用。selection
实际上返回一个代理对象,它可以表示单个或多个选择,并将任何 KVC 请求传递到底层选定的对象。它在NSObjectController
中定义,它是NSTreeController
的超类。在你的情况下,你会想要:It looks like what you want to bind to is not
selectionIndexPaths
, but instead theselection
binding. TheselectionIndexPaths
binding will return an array ofNSIndexPath
objects, which is typically only used when binding an outline/browser view's selection to the tree controller.selection
actually returns a proxy object which can represent either a single or multiple selection, and passes through any KVC requests to the underlying selected object(s). It's defined inNSObjectController
, which is a superclass ofNSTreeController
. In your case, you would want: