Re: NSTreeController Grouping Nodes - Grouping At All
Re: NSTreeController Grouping Nodes - Grouping At All
- Subject: Re: NSTreeController Grouping Nodes - Grouping At All
- From: Arved von Brasch <email@hidden>
- Date: Fri, 12 May 2006 07:47:29 +1000
On 12/05/2006, at 02:46, George Orthwein wrote:
I can't say I completely understand your set up, but one thing that
struck me was that it looks like you are creating the new group
entity as well as adding it to the NSArrayController. If the
NSArrayController values are bound to the managed object context,
then you wouldn't have to add it the array controller, right? The
table reloadData looks suspicious as well since it should update
via bindings too. I'm no expert, so perhaps there's a reason for
this I'm not seeing.
If you haven't seen it, Matt Holiday's DragAndDropOutlineEdit may
be helpful:
http://homepage.mac.com/matthol2/iblog/
That example uses an NSTreeController but the other concepts should
apply. One tip he had regarding the treecontroller:
// DO NOT use NSTreeController's insert: or insertChild: methods,
because they add objects in the
// wrong order and do not preserve the sort order (if we're sorting
in columns); also DO NOT call
// the rearrangeObjects method because objects randomly disappear
from view.
//
// In other words, ALWAYS manipulate the model directly through the
managedObjectContext and let it
// update the tree controller & outline view
Hope that might help,
George
Thank you for the response. I have looked at DragAndDropOutlineEdit,
but it seems to have a bug doing the same sort of thing I want to
do. If you create multiple top level notes (5 say), and then select
2 of them (say 3 and 4) to indent simultaneously, the indent will
fail to work correctly, and the program will hang on quitting. My
intent with grouping is to do something similar to indenting a
multiple selection.
My NSArrayController is bound to my managedObjectContext with a
predicate of "parent == nil", so it should always contain the top
level items. I can't use this directly in an NSOutlineView, because
no children would be displayed, so the columns in my NSOutlineView
are not bound to anything, instead relying on my DataSource
implementation. This explains the need for reloadData. As for
explicitly adding and removing objects form the NSArrayController, I
agree with you, I shouldn't have to do that, if my understanding of
the binding relationship to my managedObjectContext is correct. That
just happened to be the particular state the code was in when I
posted it and it also happens to be the state that causes the least
amount of run time errors. In particular, removing both explicit
notices to the NSArrayController and adding a processPendingChanges
causes the strange Article does not respond to selectors
isEqualToString: and compare: errors. Which implies a problem with
sorting inside the NSArrayController.
What I want:
• 2 level NSOutlineView
• Non grouping elements (leafs) can appear at the top level
(ungrouped) or as part of a group.
• Grouping elements can only exist at the top level and should have
at least 2 children.
• Simple grouping should create a new group element which takes on
the parent role to the current selection. (With more complex logic
if a group happens to be part of the selection).
What I've tried:
I first tried to implement this with an NSTreeController. I couldn't
get grouping to work in this situation either, and as I eventually
wanted to be able to filter the items displayed based on a search
field, I decided to try something else. This did have the advantage
of less code, because of the nice way bindings meant I didn't have to
write DataSource methods.
My second (and current) attempt is to fake it using an
NSArrayController. The NSArrayController should maintain a list of
top level elements, which I supply to my NSOutlineView through the
DataSource methods. When an group is expanded, I create a new
NSArrayController with the same filterPredicate and sortDescriptors
as my main one, but with the children of the expanded item as its
content. The contents of this ArrayController I return as for second
level OutlineView requests.
The only way I can see going from here, is to drop any controllers
completely and do it all brute force.
Cheers,
Arved _______________________________________________
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