for NSOutlineView i have tried this but it can insert only blank values in outlineview
Can anybody please help me to use NSOutlineView and NSTreeController in my cocoa application.
this is my first cocoa application so i dont understand how can i do this.
please help me foe this.
thanks .
Code:
@interface MyDataObject : NSObject
{
NSMutableDictionary *root;
id parent;
}
+(id)weakReferenceWithParent:(id)parent;
-(void)setParent:(id)_parent;
-(id)parent;
@property (assign,readonly) NSMutableDictionary *root;
@end
//-----------------------------------------------
#import "MyDataObject.h"
@implementation MyDataObject
@synthesize root;
+(id)weakReferenceWithParent:(id)parent
{
id weakRef=[[[MyDataObject alloc] init] autorelease];
[weakRef setParent:parent];
return weakRef;
}
-(void)setParent:(id)_parent
{
parent=_parent;
}
-(id)parent
{
return parent;
}
- (id)init
{
if ((self = [super init]))
{
root = [NSMutableDictionary new];
}
return self;
}
- (void)dealloc
{
[root release];
[super dealloc];
}
@end
//-----------------------------------------------
#import "MyDataObject.h"
@interface MyTableController : NSControl {
NSMutableArray * dataStore;
IBOutlet NSOutlineView* OutlineView;
}
@property (assign) NSMutableArray * dataStore;
@property (assign) NSOutlineView* OutlineView;
@end
//-----------------------------------------------
#import "MyTableController.h"
@implementation MyTableController
@synthesize dataStore;
@synthesize OutlineView;
-(NSMutableDictionary *)groupWithTitle:(id)title {
NSMutableDictionary *group=[NSMutableDictionary dictionary];
[group setObject:[NSMutableArray array] forKey:@"CHILDREN"];
if (title) [group setObject:title forKey:@"TITLE"];
return group;
}
-(NSMutableDictionary *)newItemForGroup:(NSMutableDictionary *)group title:(id)title{
NSMutableDictionary *item=[NSMutableDictionary dictionary];
id children=[group objectForKey:@"CHILDREN"];
[children addObject:item];
if (title) [item setObject:title forKey:@"TITLE"];
if (group) [item setObject:[MyDataObject weakReferenceWithParent:group] forKey:@"PARENT"];
return item;
}
-(BOOL)outlineView:(NSOutlineView *)ov isItemExpandable:(id)item {
id children;
if (!item) {
children=dataStore;
} else {
children=[item objectForKey:@"CHILDREN"];
}
if ((!children) || ([children count]<1)) return NO;
return YES;
}
-(int)outlineView:(NSOutlineView *)ov numberOfChildrenOfItem:(id)item {
id children;
if (!item) {
children=dataStore;
} else {
children=[item objectForKey:@"CHILDREN"];
}
return [children count];
}
-(id)outlineView:(NSOutlineView *)ov child:(int)index ofItem:(id)item {
id children;
if (!item) {
children=dataStore;
} else {
children=[item objectForKey:@"CHILDREN"];
}
if ((!children) || ([children count]<=index)) return nil;
return [children objectAtIndex:index];
}
-(id)outlineView:(NSOutlineView *)ov objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
return [item objectForKey:[tableColumn identifier]];
}
- (void)awakeFromNib
{
self.dataStore=[[NSMutableArray array] retain];
id group1=[self groupWithTitle:@"group1"];
id group2=[self groupWithTitle:@"group2"];
[self newItemForGroup:group1 title:@"item1"];
[self newItemForGroup:group2 title:@"item2"];
[self.dataStore addObject:group1];
[self.dataStore addObject:group2];
[OutlineView reloadData];
}
@end
Can anybody please help me to use NSOutlineView and NSTreeController in my cocoa application.
this is my first cocoa application so i dont understand how can i do this.
please help me foe this.
thanks .