NSOutlineView question solved
NSOutlineView question solved
- Subject: NSOutlineView question solved
- From: Stéphane Baron <email@hidden>
- Date: Tue, 26 Aug 2003 20:37:25 +0200
So here is my new code to fill my NSOutlineView
Huge use of isKindOfClass, not sure it is efficicent but it work.
- 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];
}
else if ([item isKindOfClass:[NSDictionary class]])
{
return [[item
objectForKey:@"mykids"]objectAtIndex:index];//////////////////////////
}
else if ([item isKindOfClass:[NSArray class]])
{
return [item objectAtIndex:index];
}
}
- (int)outlineView: (NSOutlineView *) outlineView
numberOfChildrenOfItem: (id) item
{
if (item ==nil){
return [outlineViewElements count];}
else
return [[item objectForKey:@"mykids"] count];
}
- (BOOL)outlineView: (NSOutlineView *) outlineView isItemExpandable:
(id) item
{
if ([item isKindOfClass:[NSDictionary class]])
{
if ([item objectForKey:@"mykids"])
return YES;
else
return NO;
}
else if ([item isKindOfClass:[NSArray class]])
return NO;
else if ([item isKindOfClass:[NSConstantString class]])
return NO;
else
return NO;
}
- (id)outlineView: (NSOutlineView *) outlineView
objectValueForTableColumn: (NSTableColumn *) tableColumn byItem: (id)
item
{
if([[tableColumn identifier] isEqualToString:@"nom"])
{
if (item==nil)
{
return [item objectForKey:@"myparent"];
}
else if ([item isKindOfClass:[NSDictionary class]])
{
return [item objectForKey:@"nom"];
}
else if ([item isKindOfClass:[NSArray class]])
{
return [item objectForKey:@"nom"];
}
else if ([item isKindOfClass:[NSConstantString class]])
{
return [item objectForKey:@"nom"];
}
}
if([[tableColumn identifier] isEqualToString:@"idC"])
{
if (item==nil)
{
return [item objectForKey:@"idC"];
}
else if ([item isKindOfClass:[NSDictionary class]])
{
return [item objectForKey:@"idC"];
}
else if ([item isKindOfClass:[NSArray class]])
{
return [item objectForKey:@"idC"];
}
else if ([item isKindOfClass:[NSConstantString class]])
{
return [item objectForKey:@"idC"];
}
}
}
- (NSArray *)populateDataSource
{
dataSource=[NSMutableArray array];
NSMutableArray *childs;
childs=[[NSMutableArray alloc]init];
[childs addObject:[NSDictionary
dictionaryWithObjectsAndKeys:@"nom1",@"nom",@"1",@"idC",nil]];
[childs addObject:[NSDictionary
dictionaryWithObjectsAndKeys:@"nom2",@"nom",@"2",@"idC",nil]];
[childs addObject:[NSDictionary
dictionaryWithObjectsAndKeys:@"nom3",@"nom",@"3",@"idC",nil]];
NSDictionary *dict1, *dict2, *dict3;
dict1=[NSDictionary
dictionaryWithObjectsAndKeys:childs,@"mykids",@"parent1",@"nom",@"nomA",
@"idC",nil];
dict2=[NSDictionary
dictionaryWithObjectsAndKeys:@"parent2",@"nom",@"nomC",@"idC",nil];
dict3=[NSDictionary
dictionaryWithObjectsAndKeys:@"parent3",@"nom",childs,@"mykids",@"nomB",
@"idC",nil];
[dataSource addObject:dict1];
[dataSource addObject:dict2];
[dataSource addObject:dict3];
return dataSource;
}
- (void)dealloc
{
[dataSource release];
[super dealloc];
}
_______________________________________________
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.