Re: (NEWBIE) NSOutlineView question
Re: (NEWBIE) NSOutlineView question
- Subject: Re: (NEWBIE) NSOutlineView question
- From: Philippe Prevot <email@hidden>
- Date: Mon, 25 Aug 2003 22:28:12 +0200
I think the problem is in :
- (id)outlineView: (NSOutlineView *) outlineView
objectValueForTableColumn: (NSTableColumn *) tableColumn byItem: (id)
item
{
if (item == nil)
{
return [item objectForKey:@"myparent"];
}
return [item objectForKey:@"mykids"];
}
When you must display the child you return an array but you should
return "item" itself as it already contains the string you must display.
Philippe Privot
Le lundi, 25 ao{ 2003, ` 21:48 Europe/Paris, Stiphane BARON a icrit :
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",ni
l
];
dict2=[NSDictionary
dictionaryWithObjectsAndKeys:@"parent2",@"myparent",nil];
dict3=[NSDictionary
dictionaryWithObjectsAndKeys:@"parent3",@"myparent",childs,@"mykids",ni
l
];
[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.
_______________________________________________
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.