如何使用 Cocoa Bindings 实现基于视图的源列表 (NSOutlineView) 的示例?
有没有人找到关于如何使用 Lion 中引入的基于视图的 NSOutlineView 实现源列表的清晰、简洁的示例或指南?我看过苹果的示例项目,但没有任何方向感或解释,我发现很难掌握它们到底如何工作的概念。
我知道如何使用优秀的 PXSourceList 作为后备,但如果可能的话,我真的很想开始使用基于视图的源列表。
Has anybody found a clear, concise example or guide on how to implement a source list using the view-based NSOutlineView introduced in Lion? I've looked at Apple's example project, but without any sense of direction or explanation, I'm finding it difficult to grasp the concept of exactly how they work.
I know how to use the excellent PXSourceList as a fallback, but would really like to start using view-based source lists instead if at all possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您用 cocoa-bindings 标签标记了它,所以我假设您的意思是“带有绑定”。我举了一个简单的例子。从 Xcode 中新的非基于文档的 Cocoa 应用程序模板开始。随便你怎么称呼它。首先,我添加了一些代码来绑定一些假数据。这是我的 AppDelegate 标头的样子:
这是我的 AppDelegate 实现的样子:
我创建的假数据结构没有特别的意义,我只是想展示一些带有几个子级别的东西,等等。唯一重要的是是您在 Interface Builder 的绑定中指定的键路径与数据中的键(在本例中为假数据)对齐。
然后选择
MainMenu.xib
文件。在 IB 编辑器中,执行以下步骤:.xib
中。children
(对于本例;对于您的数据,这应该是返回子对象数组的任何内容。)dataModel
.xib
。基于视图
1
来源列表
静态文本 - 表视图单元格
。Table Cell View
,模型键路径:objectValue.itemName
(我已经在假数据中使用了itemName
,您需要使用与数据项名称相对应的键)保存。跑步。您应该看到一个源列表,一旦您展开了带有子节点的节点,您可能会看到如下内容:
加入了 Apple 开发者计划,您应该能够访问 WWDC 2011视频。有一个专门致力于使用基于视图的 NSTableView(和 NSOutlineView),并且它包含相当全面的绑定覆盖。
希望有帮助!
You tagged this with the cocoa-bindings tag, so I assume you mean "with bindings." I whipped up a quick example. Start from a new non-document-based Cocoa Application template in Xcode. Call it whatever you like. First I added some code to make some fake data to bind to. Here's what my AppDelegate header looks like:
And here's what my AppDelegate implementation looks like:
There's no particular significance to the fake data structure I created, I just wanted to show something with a couple of sub-levels, etc. The only thing that matters is that the key paths you specify in the bindings in Interface Builder line up with the keys in your data (fake data in this case.)
Then select the
MainMenu.xib
file. In the IB editor, do the following steps:.xib
.children
(for this example; For your data, this should be whatever returns the array of child objects.)dataModel
.xib
.View Based
1
Source List
Static Text - Table View Cell
.Table Cell View
, Model Key Path:objectValue.itemName
(I've useditemName
in the fake data, you would want to use whichever key corresponded to the name of your data items)Save. Run. You should see a source list, and once you've expanded the nodes with children, you might see something like this:
If you're in the Apple Developer Program, you should be able to access the WWDC 2011 Videos. There's one specifically dedicated to working with View-based NSTableView (and NSOutlineView) and it includes pretty thorough coverage of bindings.
Hope that helps!
看一下这个例子。
SideBarDemo
Take a look at this example.
SideBarDemo