Re: Expanding outline view item ancestry
Re: Expanding outline view item ancestry
- Subject: Re: Expanding outline view item ancestry
- From: Corbin Dunn <email@hidden>
- Date: Fri, 15 Aug 2008 14:59:46 -0700
Hey António
On Aug 15, 2008, at 2:37 PM, Antonio Nunes wrote:
Hi,
Although there is a fair number of posts referencing "expandItem" I
couldn't quite find this in the archives, although I had expected it
to be a fairly common scenario:
I search for an item that belongs to a tree that is shown in an
NSOutlineView. When I find the item, I want the outline view to show
the it (if it is currently collapsed) and select its row. For that I
wrote the following code, that should ensure the selected item's
ancestry is expanded, and then selects the targeted item:
while (currentOutline.parent != nil) {
currentOutline = currentOutline.parent;
[clerkDocument.outlinesOutlineView expandItem:currentOutline];
}
[clerkDocument.outlinesOutlineView selectRowIndexes:[NSIndexSet
indexSetWithIndex:[clerkDocument.outlinesOutlineView
rowForItem:match]] byExtendingSelection:NO];
Running this through the debugger I checked that each ancestor of
the item gets expanded, and the code executes correctly. However, if
several of the ancestors were collapsed, then after this code above
is executed the outline only ends up expanding the top previously
expanded ancestor, and the targeted item doesn't get selected
(because there is no row for item "match" since it is not visible).
All the ancestors have been set to expand though.
Is there anything wrong with my understanding of how NSOutlineView
operates in this respect,
Yes.
NSOutlineView only "knows" about items that you can physically see (if
you scrolled around). Children of non expanded items are not known to
the NSOutlineView -- for it to know that, it would have to recurse and
cache all children for any potentially expandable node. That's not
feasible.
or could this be a bug in NSOutlineView, and if so, is there a
workaround?
No, it's not a bug, so there isn't a workaround per say. But, I can
help you do it right. As you walk to your parent, add each item to an
array at the start. Then, walk the array and expand each item in it.
corbin
António
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden