Hi all, I'm trying to use NSOutlineView. I have created one database with one tables using QuickLite having the columns Name, Address, Country, Phone. Now I just want to display the contents of Country column and Name column of table in outlineview with Country as root and all the Name that are having the same Country name as its children. I used the code like:
- (id) init { @try{ int i,j; Node *child, *temp;
self = [super init]; NSString* filePath = [NSString stringWithFormat: @"%@/%@", @"MyFolder", @"Employee"];
db = [[QuickLiteDatabase databaseWithFile: [filePath stringByExpandingTildeInPath]] retain];
if ([db open]) {
QuickLiteCursor* cursor = [db performQuery
"select distinct Country from Contact;"];
for(i=0;i<[cursor rowCount];i++) {
QuickLiteRow* row =[cursor rowAtIndex:i];
NSString* country =[row valueForColumn
"Contact.Country"];
child = [Node new];
[child setName:country];
QuickLiteCursor* childCursor =[db performQuery:[NSString stringWithFormat
"select Name from Contact where Company='%@'",country ]];
for(j=0;j<[childCursor rowCount];j++) {
QuickLiteRow* childRow =[childCursor rowAtIndex:j];
NSString* name =[childRow valueForColumn
"Contact.Name"];
temp = [Node new];
[temp setName: name]; // here comes the error//
[child addChild: temp];
[temp release]; }
[root addChild:child]; [child release]; } }
} return self; } @catch(NSException* ex) { NSLog(@"main %@, caught %@",[ex name],[ex reason]); }
/////And in the Node class I coded like - (id) init { self = [super init];
children = [NSMutableArray new];
return self; }
- (void) setName: (NSString *) string { name =string; }
- (NSString *) name { return name; }
- (NSString *) value { return value; }
- (void) addChild: (id) child { [children addObject: child]; }
- (NSArray *) children { return children; }
- (void) dealloc { [super dealloc]; }
My problem is when I trying to set the name in init method like: [temp setName: @"any string"]; it works properly with displaying 'any string' in outline view. But when I try to set name from database it shows only the root nodes. When I expanding the root node the application hangs and get closed. What is the problem with my code ? How can I solve this ?