Hey all
I am pulling my hair out trying to work out how to convert a category list into a data model for a NSOutlineView.
I am attempting to create a Source view / NSOutlineView to let a user select a product category. Just like a tree view. There are no Leaf nodes, just roots and branches.
The user entered data is stored in an SQLite table as the following:
Three could be 20 or 1000 of these records, the user is allowed to add and delete them.
So we can see there are 2 root nodes (Ford, Honda) and various branches and branches of branches (Turbo, XR2)
So, for the data model I created a class to hold the data as in:
What I can't figure out is how to traverse the SQLite data and store it in the class object. I get muddled up when it comes to children of children.
Any help would be much appreciated.
I am also using FMDB as an SQLite wrapper.
Many thanks
Anim
I am pulling my hair out trying to work out how to convert a category list into a data model for a NSOutlineView.
I am attempting to create a Source view / NSOutlineView to let a user select a product category. Just like a tree view. There are no Leaf nodes, just roots and branches.
The user entered data is stored in an SQLite table as the following:
Code:
ID PRODUCT PARENTID
1 FORD 0
2 HONDA 0
3 FIESTA 1
4 XR2 3
5 ESCORT 1
6 CIVIC 2
7 TURBO 6
Three could be 20 or 1000 of these records, the user is allowed to add and delete them.
So we can see there are 2 root nodes (Ford, Honda) and various branches and branches of branches (Turbo, XR2)
So, for the data model I created a class to hold the data as in:
Code:
#import <Foundation/Foundation.h>
@interface BP_category : NSObject
@property (copy) NSString *categoryName;
@property (readonly, copy) NSMutableArray *subCategory;
-(id)initWithName:(NSString *)name;
-(void)addChildCategory:(BP_category *)c;
@end
------------------
#import "BP_category.h"
@implementation BP_category
-(id)init {
return [self initWithName:@"Untitled"];
}
-(id)initWithName:(NSString *)name {
self = [super init];
if (self) {
_categoryName = [name copy];
_subCategory = [[NSMutableArray alloc]init];
}
return self;
}
-(void)addChildCategory:(BP_category *)c {
[_subCategory addObject:c];
}
@end
What I can't figure out is how to traverse the SQLite data and store it in the class object. I get muddled up when it comes to children of children.
Any help would be much appreciated.
I am also using FMDB as an SQLite wrapper.
Many thanks
Anim