Having a table and outline work togethor
Having a table and outline work togethor
- Subject: Having a table and outline work togethor
- From: Coleman Nitroy <email@hidden>
- Date: Mon, 20 Dec 2004 15:33:29 -0500
I have been working for a bit on getting a proper data source working for a outline view. I am aware that an outline view cannot use bindings, but a table can. I have a leaf/node style structure to contain all of my data. Each and every node and leaf has a dictionary in it. Basically I want to make it so if the user selects something from the outline view, the tableview shows the dictionary in two columns, keys and values. So i only want one node displayed at a time. This also needs to be editable, and I would love to do this with bindings but am not sure how to go about doing so. The first problem I have is getting the outline view to work at all. Here is what I am currently doing. Being new to cocoa and its been awhile since I last coded I am having some troubles coming up with good "kosher" ways to have the data thrown around in the application. All suggestions are greatly appreciated. Begin the fun code:
MapNode.m
((I wont display this code because its long complex and tested to work))
MapNode basically takes in an NSData object and creates a root node and builds the node tree structure. I have a debugging function after its all loaded climbing the newly created tree and NSLogging everything in the tree and it is all in tact.
MapDataSource.m
- (void) initWithContents: (NSData *) data
{
// Each node has a NSString as an identifier for debugging
[rootNode setNodeName: @"Root"];
// Build a tree with the data
[rootNode createTree: data];
// Debugging function that spits out the entire tree
[rootNode printNodeChildren:rootNode];
}
((I wrote my own then got frustrated and tossed in the code from OutlineMe from Hillegass's example and modified it))
- (id)outlineView:(NSOutlineView *)ov child:(int)index ofItem:(id)item
{
if (item)
// Return the child
return [item childAtIndex:index];
else
// Else return the root
return rootNode;
}
// Called repeatedly to find out if there should be an
// "expand triangle" next to the label
- (BOOL)outlineView:(NSOutlineView *)ov isItemExpandable:(id)item
{
// Returns YES if the node has children
return [item expandable];
}
// Called repeatedly when the table view is displaying itself
- (int)outlineView:(NSOutlineView *)ov numberOfChildrenOfItem:(id)item
{
if (item == nil) {
// The root object;
return 1;
}
return [item childrenCount];
}
// This method gets called repeatedly when the outline view is trying
// to display it self.
- (id)outlineView:(NSOutlineView *)ov
objectValueForTableColumn:(NSTableColumn *)tableColumn
byItem:(id)item
{
return [item nodeName];
}
// This method gets called when the user edits the field.
- (void)outlineView:(NSOutlineView *)ov
setObjectValue:(id)object
forTableColumn:(NSTableColumn *)tableColumn
byItem:(id)item
{
[item setNodeName:object];
[outlineView reloadItem:rootNode reloadChildren:YES];
}
MapDocument.m
((has a MapDataSource object and passes it the data loaded from an open dialog))
TreeviewController.m
((controller for the particular nib file that the outline view is in, contains code to load the nib thats it))
((I am not sure what class this particular nib's file owner should be?))
IntrerfaceBuilder Stuff:
The outlineview is connected to MapDataSource as its data source.
Sorry if this is rather complex or not very verbose. Ill gladly answer any questions about this, anything to get this up and running properly.
Thanks in advance,
---
Coleman Nitroy
email@hidden
nitroy.com/cole
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden