epreston / PSTreeGraph

A tree graph view control for iPad applications. This is a port of the sample code from Max OS X to iOS (iPad).
http://epreston.github.io/PSTreeGraph/
259 stars 50 forks source link

How to add new objects to tree and refresh #6

Open TheLearner opened 13 years ago

TheLearner commented 13 years ago

Absolutely fantastic control! Forgive me for creating an issue, as I just really want to ask you a question.

How do I add a new item to the tree and refresh the tree to show the new item while the app is running.

epreston commented 13 years ago

Thank you for the feedback. :-)

I think I'll join you on this one. :-) That's the perfect scope for exercising this thing. In the process, we'll create some more examples, review the control, and add more documentation to the wiki.

Until I get a few hours to cut some code and markup some thoughts, start with this;

Quick Tour:

This sample is using the MVC (model view controller) pattern. The view part is the control, the model part is some clever class that gets information from the objective-c runtime on registered classes, and the controller part is a UIViewController. The controller is the glue between them that knows about both.

Important to Know:

Where to start:

In short, you want to swap out data models, customise the leaf views, add some code to modify data model nodes.

The data model is simple, just implement the two methods of the protocol. The rest should be done in a sub class like PSHLeafView. This is an example subclass that has an expand collapse button. Its best practice to create a subclass like it and make your changes there. In the example, you can change the leaf views appearance quickly by editing ObjCClassTreeNodeView. Modifying the PSHTreeGraphViewController will tie your model and display together.

We'll have to put some thought into how we implement the add / edit.

Shopping List:

epreston commented 13 years ago

It is much easier to follow the conversation if you post responses into new comments instead of editing the original post. Cheers :-)

TheLearner commented 13 years ago

Hi there, apologies for modifying the original post won't happen again.

Cheers for helping me with this it will be fantastic if we can get this working.

So far I have created my own data model 'EntityModel' and created the add button and managed to get it loading with dummy items (which will eventually come for a data source) etc but the main thing I am totally unsure about how to get going is basically adding new items and refreshing.

My requirements for the control have changed slightly in that I am picturing this scenario:

"The control loads and there is a single node visible. The user can tap the add button and create any number of sub nodes. The user can then tap on a particular node and a popovercontroller appears and allows the user to edit the title, description, type and any other fields as well. When the popovercontroller disappears it updates the node."

How are you picturing actually refreshing a node/the control to show new items?

TheLearner commented 13 years ago

Hi Ed, do you perhaps have a few pointers or ideas to get be started on the adding/refreshing? Really want to use this control but not sure where to go from here.

Cheers,

TheLearner commented 13 years ago

Hi Ed,

Just to let you know I implemented refresh but I am sure you will think its a serious hack but at this stage it works and is the only way I could think of doing it.

Basically when you call SetRootNode instead of passing it the root node, it asks the delegate for the rootnode. This way I can call this method anytime I need a refresh.

Works okay except when there many shapes on the view then it looks a bit dodgy.

Looking forward to hearing your ideas :)

evanlucas commented 12 years ago

I also needed a control that allowed on the fly refreshing. I created a modified version that allows one to add new nodes to the tree and refresh the tree. The modified version also allows one to create the node view's without using nibs, just to make it a little different. Check out https://github.com/evanlucas/TreeNodeControl. Thanks for the work you did to port this over to iOS.

epreston commented 12 years ago

Your welcome. I agree it really should support a dynamic refresh. In addition, I think it should support multiple animation styles. I plan to have a tilt at it in an effort to modernise the objective-c, reduce the size of the code base, and add more features.