Skip navigation.
 
mlRe: Source list using bindings?
FROM : Jonathan Dann
DATE : Tue Mar 25 22:49:23 2008

> Ah, thanks. I wonder what the purpose of this subclass is and how
> fragile this solution?


As of 10.5 it's the Apple-sanctioned way to go!  I've used it for ages 
now, no problems at all.  The tree node is a proxy for whatever 'real' 
item you add to the tree.

You can also get the selectedNodes, which returns treeNode objects, or 
the selectedObjects, which returns the 'real' obejcts that you've 
created.

My isGroupItem just compares an NSString *nodeName of the represented 
object to a list of strings I want to have as groups, i.e @"SOURCES", 
@"PLAYLISTS", etc.

>
> I'm not convinced I'm going to go the bindings route, as my source
> list has non-collapsible groups, and making sure they're expanded and
> not selected when the table is first displayed seems as much trouble
> as just using a datasource in the first place!
>


Bindings do make the whole thing a lot easier in the long run, and 
autosaving of the state just needs a bit of trickery:

1) Subclass NSOutlineView and add a method that simply looks at each 
row in turn and sees if the itemAtRow is expanded.

2) Add all the expanded items to an array.

3) Save the array in your data store, along with the whole tree as you 
normally would.

4) On loading, set the outline view's content and then pass the 
'expanded items' array to another method 'expandItemsInArray' in you 
NSOutlineView subclass.

5) This method should start at row 1 and compare all the items in the 
expanded items array to the itemAtRow: if they're the same expand the 
item

6) When you do this, be sure to update the number of rows as each 
expansion of an item causes the number of rows to increase.

This works without fail for me, i posted the code that does this a 
while back, sometime in the last couple of months.

Hope this helps,

Jon

Related mailsAuthorDate
mlSource list using bindings? Hamish Allan Mar 25, 02:42
mlRe: Source list using bindings? Rob Keniger Mar 25, 07:20
mlRe: Source list using bindings? Hamish Allan Mar 25, 22:07
mlRe: Source list using bindings? Jonathan Dann Mar 25, 22:49
mlRe: Source list using bindings? Hamish Allan Mar 26, 01:45
mlRe: Source list using bindings? Jonathan Dann Mar 26, 20:59