我可以使用 NSDictionaryController 作为字典的字典吗?
我有一个 plist 文件,其中包含我需要在组织为字典字典的应用程序中显示的信息。我刚刚开始对 Cocoa 进行编程,所以不确定最好的方法。显然,我可以手动完成这一切,并对循环进行编码并将数据添加到 UI 元素,但在我看来,绑定和提供的控制器应该让我更容易地做到这一点。
我特别想知道是否有一种直接的方法(例如主要使用 Interface Builder)来链接我从读取 plist 文件中获得的 NSDictionary ,该文件本身包含更多的 NSDictionary 元素,其中又包含名称-值字符串对,到适当的用户界面元素——可能是大纲视图或浏览器。
或者,数据将适合函数浏览器类型面板(如 Excel 中),其中顶级键是函数类别,下一级是该类别中的函数,我可以使用最低级别的详细信息填充文本区域-- 即来自最终字典的值数据。
I have a plist file that holds information I need to display in an app organised as a dictionary of dictionaries. I've just started programming Cocoa so am not sure the best way to go about this. Obviously I can do it all manually, and code up the loops and add the data to the UI elements, but it seems to me that bindings and the provided controllers should let me do this more easily.
I was specifically wondering if there was a direct way (e.g. using mostly Interface Builder) to link the NSDictionary
I get from reading the plist file, that itself contains further NSDictionary
elements, which in turn contain name-value string pairs, to an appropriate user interface element -- probably an outline view or a browser.
Alternatively, the data would fit into a function browser type panel (like in Excel) where the top level keys are categories of functions, the next level are functions in that category, and I can just populate a text area with the lowest-level details -- i.e. the value data from the final dictionary.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你无法使用 NSBrowser 或 NSOutlineView 来做到这一点。我这么说的原因是因为如果您使用这些视图的绑定,则需要使用 NSTreeController。 NSTreeController 提供了指定模型中哪些键指示当前对象是否有子对象(isLeaf)以及如何访问子对象(children)的能力。
因此,如果您要使用这两个视图之一,则必须能够向模型添加其他键和属性才能执行此操作。很多时候,当我使用 NSOutlineView 和 NSBrowser 时,我发现最简单的方法是完全跳过绑定,只使用 all delegate & 。数据源方法。它们需要更多的代码,但它们并不难组合在一起,有时,如果我的数据模型很复杂,或者数据不是很容易通过 NSTreeController 传输的格式,我更喜欢它们而不是绑定。
但是,您可以通过执行以下操作来使用 NSTableView。
I don't think you are going to be able to do this with an NSBrowser or NSOutlineView. The reason I say that is because if you are using bindings with those views you need to use an NSTreeController. NSTreeController provides the ability to specify which keys in your model indicate whether or not the current object has children objects (isLeaf) and how to access the children objects (children).
So if you are going to use one of those two views, you must be able to add additional keys and properties to your model to do so. Many times when I work with NSOutlineView and NSBrowser I find it easiest to skip bindings altogether and just use the all delegate & datasource methods. They require more code but they aren't hard to put together and sometimes I prefer them to bindings if my data model is complex or if the data is not in a format that is easily pumped through an NSTreeController.
However you could use an NSTableView by doing the following.