(NEWBIE) NSOutlineView question
(NEWBIE) NSOutlineView question
- Subject: (NEWBIE) NSOutlineView question
- From: Stéphane BARON <email@hidden>
- Date: Mon, 25 Aug 2003 21:48:20 +0200
I try to display in an NSOutlineView the data as shown in the code
below.
If i trace my code with NSlog the outlineview know when:
an item is parent or child and if it is child the number of chil item.
So i don't understand why my NSOutlineView is not correctly displayed
(the list of the child item if the item is a parent and an empty cell
if the item is a parent with no child.)
Can someone help please ???
(i have looked for the apple example , also the bignerdranch to)
S. Baron
My code:
@implementation OVDataSource
- init
{
[super init];
outlineViewElements = [[NSMutableArray alloc] init];
[outlineViewElements setArray:[[self populateDataSource]retain]];
return self;
}
- (id) outlineView: (NSOutlineView *) outlineView child: (int) index
ofItem: (id) item
{
if (item == nil)
{
return [outlineViewElements objectAtIndex: index];
}
return [[item objectForKey:@"mykids"] objectAtIndex: index];
}
- (int)outlineView: (NSOutlineView *) outlineView
numberOfChildrenOfItem: (id) item
{
if (item == nil) return [outlineViewElements count];
return [[item objectForKey:@"mykids"] count];
}
- (BOOL)outlineView: (NSOutlineView *) outlineView isItemExpandable:
(id) item
{
if ([[item objectForKey:@"mykids"] count] > 0) return YES;
return NO;
}
- (id)outlineView: (NSOutlineView *) outlineView
objectValueForTableColumn: (NSTableColumn *) tableColumn byItem: (id)
item
{
if (item == nil)
{
return [item objectForKey:@"myparent"];
}
return [item objectForKey:@"mykids"];
}
- (NSArray *)populateDataSource
{
dataSource=[NSMutableArray array];
NSMutableArray *childs;
childs=[[NSMutableArray alloc]init];
[childs addObject:@"child1"];
[childs addObject:@"child2"];
[childs addObject:@"child3"];
NSDictionary *dict1, *dict2, *dict3;
dict1=[NSDictionary
dictionaryWithObjectsAndKeys:@"parent1",@"myparent",childs,@"mykids",nil
];
dict2=[NSDictionary
dictionaryWithObjectsAndKeys:@"parent2",@"myparent",nil];
dict3=[NSDictionary
dictionaryWithObjectsAndKeys:@"parent3",@"myparent",childs,@"mykids",nil
];
[dataSource addObject:dict1];
[dataSource addObject:dict2];
[dataSource addObject:dict3];
return dataSource;
}
- (void)dealloc
{
[dataSource release];
[super dealloc];
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.