strange problem with NSOutlineView
strange problem with NSOutlineView
- Subject: strange problem with NSOutlineView
- From: Nikolay Ilduganov <email@hidden>
- Date: Fri, 3 Oct 2003 13:35:15 +0700
Hello!
I've wrote datasource for outline view. Function void testnames(void
(*callback(char *))) from C library, and it calls callback to add names
to collection.
Then I create NSString from C-string and put it into collection. I
think I should release NSString after adding. But it results in failure
of my program. Then I try to not release NSString, the same result when
I click to outline view. Retaining NSString before adding solved my
problem, but I dont understand why.
May be I should duplicate C-string before adding?
Please help me with this simple problem.
Code below.
static DataSource *datasource;
void callback(char *name)
{
[datasource addName:name];
}
@implementation DataSource
- (id)init
{
self = [super init];
names = [NSMutableArray arrayWithCapacity: 1];
datasource = self;
test_names(callback);
return self;
}
- (void)dealloc
{
datasource = 0;
[names release];
[super dealloc];
}
- (void)addName:(char *)name
{
NSString *bsd_name = [NSString stringWithCString:name];
[bsd_name retain]; // why???
[names addObject:bsd_name];
}
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index
ofItem:(id)item
{
if(item == nil) { return [names objectAtIndex:index]; }
else { return nil; }
}
- (BOOL)outlineView:(NSOutlineView *)outlineView
isItemExpandable:(id)item
{
return NO;
}
- (int)outlineView:(NSOutlineView *)outlineView
numberOfChildrenOfItem:(id)item
{
if(item == nil) { return [names count]; }
else { return 0; }
}
- (id)outlineView:(NSOutlineView *)outlineView
objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
return item;
}
@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.