Reputation: 9979
I need to represent my data like a Tree structure in UI.How can I create a view like this in iPhone? Is there any default items for this in object library
? If no how can I manually implement this?
Upvotes: 4
Views: 1448
Reputation: 1622
There is a project on github called PSTreeGraph made by Ed Preston
https://github.com/epreston/PSTreeGraph
Author says that it is for iPad but work also on iPhone, simply by changing the device to iPhone in xcode "deployment info"
In addition, it's interactive.
EDIT
Possibility to add node "manually":
In PSHTreeGraphViewController.m
you have an entry point [self setRootClassName:@"UIControl"];
here you can check how to create the tree.
That project also gives you data model : ObjCClassWrapper
And finally there is a method (delegate)
-(void) configureNodeView:(UIView *)nodeView
withModelNode:(id <PSTreeGraphModelNode> )modelNode
called on a node tap.
Everything to create a custom interactive tree!
Upvotes: 3
Reputation: 1225
There is in Core Foundation something like CFTree
But, to be honest, I wouldn't use it, because it is too low level and it's in pure C. It would be better to implement tree structure by your own.
You can achieve it in many different ways, depending on what kind of tree you want to have. Here is an example of the easiest interface:
@interface XYNode : NSObject
@property(nonatomic, readonly) YourDataObjectType *data;
@property(nonatomic, readonly) NSSet *children;
@property(nonatomic, readonly) XYNode *parent;
+ (instancetype)nodeWithParent:(XYNode *)parent data:(YourDataObjectType *)data;
- (instancetype)initWithParent:(XYNode *)parent data:(YourDataObjectType *)data;
- (void)addChildNode:(id)node;
- (void)removeChildNode:(id)node;
@end
Upvotes: 4