Re: Help - Outline view woes
Re: Help - Outline view woes
- Subject: Re: Help - Outline view woes
- From: April Gendill <email@hidden>
- Date: Sun, 29 Feb 2004 13:55:37 -0700
Yes actaully, this helped a lot. Mostly because your example was very
similar to the data structure I used.
Anyway made a couple of changes and now the root does not display in
the view, the children of root and their children do, so it works like
I wanted it to.
and I can add things anywhere I want. (still not sure how that works
but it works so I'll figure it out as I go.)
On Feb 29, 2004, at 12:34 PM, Todd Lair wrote:
Let's say you have an array of root items called array. Inside this
array is instances of class type A. A has a method called - (NSArray
*)subitems. This returns an array of child items inside A that are of
class type B, let's say.
Hope this helps.
You could then implement your outline view methods like this:
- (int)outlineView:(NSOutlineView *)ov numberOfChildrenOfItem:(id)item
{
// this is called with item == nil when asking how many root items
there are
if (item == nil)
return [array count]; // return the number of A's we have
// Here, item will be an A, so we return the count of A's items
return [[item subitems] count];
}
- (BOOL)outlineView:(NSOutlineView *)ov isItemExpandable:(id)item
{
// this is called to ask if a particular item has any child items
// to determine this, we need to know if it is an A which might have
some,
// or a B, which doesn't have any. This will be called to see if
numberOfChildrenOfItem
// should be called on the item passed in to determine how many.
// Ours, only A's are potentially expandable. They also have to have
some subitems
return [item isKindOfClass:[A class]] && [[item subitems] count] > 0;
}
- (id)outlineView:(NSOutlineView *)ov child:(int)index ofItem:(id)item
{
// Here, the outline view is asking for the whole child item. Not
values
// within it yet. In our case, both the single root item (nil) and
A's have
// childs. This is called after asking numberOfChildrenOfItem. We
return
// the children themselves here. When passed nil for item, the
outline view
// is asking for the root level items
// Asking for A's
if (item == nil)
return [array objectAtIndex:index];
// Here, item is an A, and it's asking for our B child item at the
index
if ([item isKindOfClass:[A class]])
return [[item subitems] objectAtIndex:index];
// shouldn't get here
return nil;
}
- (id)outlineView:(NSOutlineView *)ov
objectValueForTableColumn:(NSTableColumn *)tc
byItem:(id)item
{
// Finally, as the last step, this method is called to get the actual
// values (or display items) for a instance of A or B
// You can do special cases based on whether you are passed an A or B
// or simply make this a one liner by calling return [item
valueForKey:[tc identifier]],
// but both A and B have to have the supporting interfaces
implemented the same.
// if there is some difference, or you want to trap different things
depending on
// which class you are passed as item, you can also check here...
if ([item isKindOfClass:[A class]])
{
// Do something special for A's here to calculate value
// (I'm getting lazy though)
return [item valueForKey:[tc identifier]];
}
if ([item isKindOfClass:[B class]])
{
return [item valueForKey:[tc identifier]];
}
// won't get here
return nil;
}
On Feb 29, 2004, at 1:52 PM, April Gendill wrote:
Ok... I am really bad with outline views. Let me start with this..
Yes I did read the docs and yes I did look at the examples and I know
less now than I did before I read the docs and looked at the
examples.
So my plea for help is as follows:
First off : I have tried a node structure similar to those in the
examples but it simply does not work. I really hate the examples...
The apple examples took a stupid short cut and rather than actually
typing the information out they defined it and just use NODE_DATA()
so I totaly have no idea what I'm looking at. The4 examples from my
books also use this node structure format but some how thee is a
magic I don't understand because their data source magically knows
what info to pass where as mine does not. (And yes at this point as
far as I'm concerned this is all magic.)
Second : How do I return the data to the view for display because
outline views down reference indecies or keys or anything.. they
reference item, how the hell to I find out what "item" is if I don't
have any common point of reference? Tables are 1 dimensional and
simple it's just an array index, but outlines look like they are
meant to handle dictionaries.. However none of the examples use a
dictionary they use some whack tree node structure thing that is so
confusing to me I cant even begin to grasp it.
Third: I have been tinkering with a test project that uses an outline
view but since I cannot make it work (probably the fault of a flawed
data structure since I don't get it), the test project does not
function. Would any one be willing to take a look at the project at
note what my mistakes are? I don't want another example. I'd like to
know why MY data structure fails. I understand the format of MY
structure, I have a damn good idea how to get data out of it and with
NSLog I can. I just don't know how to pass the correct information to
the view. I need assistance getting MY data to be correctly displayed
in the outline view
Thanks
April.
_______________________________________________
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.
_______________________________________________
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.