-
Notifications
You must be signed in to change notification settings - Fork 50
How can I represent an array of strings in PSTreeGraph ? #24
Comments
You can use anything as a data source so long as it supports the simple protocol. The code in the example has a class that queries the class hierarchy to implement the two required methods. If I was working with an array of strings, I'd try two things: create a wrapper object that implemented the protocol, or add a category to my string array. As long as your data source understands the hierarchy and can be told where to start, everything else is automatic. I really learned a lot porting this code from the OSX example. I liked its design in this regard. We never need to use methods to add and remove nodes, just make the data source smart enough to describe itself. When the data source changes, the graph can be told to update itself. The important point in this design is that your GUI and controller code can focus on updating your data model, without ever worrying about the display. I think representing nested collections / arrays of strings would be a good example for the control. Something that displays the contents of a plist, would be good. |
To get things up and running we have two steps:
Specificly, you'll need to implement the "PSTreeGraphModelNode" protocol in your data object (you could add it as a category on NSMutableDictionary) or create a wrapper object that understands your data structure and can implement the two methods. You can find this defined and documented in "PSTreeGraphModelNode.h" For your data structure of nested dictionaries, implementing the "childModelNodes" function should be easy because the dictionary exposes methods that return NSArrays. Remember to check the API documentation because the protocol requires an empty array, not nil. You may need to add a quick check. To customize the display of the the nodes, take a look at how the PSTreeGraphDelegate works. This function is called to populate a view with the data of an object in your data model. It will give you the reference to the view and data model object that are being matched up. This can be as simple or as complex as you need. The example uses sub-classes to keep things clean, separating library code from the customizations needed by the project. Creating custom node displays can be done programmatically or through interface builder. You can further customize the appearance by setting properties such as orientation and color. |
I need to represent an array of strings in tree like structure. How can I do this with PSTreeGraph? I couldn't find any function for adding arbitrary nodes. Please explain.
The text was updated successfully, but these errors were encountered: