Re: Finding the parent of an outline view item
Re: Finding the parent of an outline view item
- Subject: Re: Finding the parent of an outline view item
- From: Mike Ferris <email@hidden>
- Date: Sat, 11 Jan 2003 10:40:35 -0800
NSOutlineView can and does know this about items it currently is
tracking (which is not all the items, usually), but it exposes no
direct API for it. The "hack" you mentioned is the best way to do it
if you have no way to ask the dataSource itself. The simplest way is
to start at the row of the child and go up the rows until you find the
first one whose level is one less than the level for the child row
itself.
It might be nice for outline view to have API to fetch this, but it
would have to be documented that the API might not work even for real
items since it can really only answer for items it has queried the
dataSource about, and the dataSource gets queried only as needed.
Note that using the same item for multiple rows (which would be a
possible consequence of an item having multiple parents) is bound to
really confuse NSOutlineView eventually. If you have this structure in
your underlying data, you really ought to create separate items for
NSOutlineView to use. Each row in an outline needs a unique item
(unique in the sense of different pointers.)
Mike
Begin forwarded message:
From: Joseph Jones <email@hidden>
Date: Fri Jan 10, 2003 8:59:55 PM US/Pacific
To: Cocoa Dev <email@hidden>
Subject: Finding the parent of an outline view item
Hi,
I was wondering if there was a way to find the parent of an outline
view item using outline view itself? Normally, I would just use the
datasource for the view, but I have an issue where my child elements
are children of more than one parent. This leads to an issue where,
when the view is requesting data from a child and that data is
dependent on which parent this particular item is for, I have no idea
how to calculate it.
I have a little hack where I walk from the current item's row back
till I find the parent item (using isKindOfClass, though levelForRow
is just as good here). This hack works, but I hate having to do it
every time I get requests for the data. It seems to me that
parent-child relationships are something that outline view would need
to track, but I could be wrong on that account.
Any help would be appreciated.
TIA,
Joe
_______________________________________________
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.