Discussion in 'Mac Programming' started by mahaboob, Aug 6, 2008.

  1. mahaboob macrumors member

    Jul 10, 2008
    Hi all,
    I'm new to cocoa. I'm trying to work with NSOutlineView. I created two databases using QuickLite and few tables in it. Now I want to display this in outlineview. I want to display the databases as root nodes and the tables as its children. I read the documentations about NSOutlineView but, I didn't got the idea to set the data source. How can I do this?

    Thanks in advance.
  2. HerQ macrumors newbie

    Jun 11, 2008
    The Netherlands
    You'll probably have to search for NSTreeController, a class new in Leopard. There are some eamples from Apple and many others, too.

    Good luck!
  3. mahaboob thread starter macrumors member

    Jul 10, 2008
    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:mad:"select distinct Country from Contact;"];
    for(i=0;i<[cursor rowCount];i++) {
    QuickLiteRow* row =[cursor rowAtIndex:i];
    NSString* country =[row valueForColumn:mad:"Contact.Country"];
    child = [Node new];
    [child setName:country];
    QuickLiteCursor* childCursor =[db performQuery:[NSString stringWithFormat:mad:"select Name from Contact where Company='%@'",country ]];
    for(j=0;j<[childCursor rowCount];j++) {
    QuickLiteRow* childRow =[childCursor rowAtIndex:j];
    NSString* name =[childRow valueForColumn:mad:"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 ?

Share This Page