Expanding all Nodes in an NSOutlineView on Load

  • Hi,

    I have an NSOutlineView showing sources in the same way as iTunes 7,
    which 'header rows' for "Places", "Smart Lists", etc.

    On opening a new or previous document, I would like the outlineview to
    expand all its nodes. I have written the method to do this, and
    checked it works by hooking it up as an IBAction. However, when I call
    the method from within one of the two initialisation delegates, e.g:

    - (void)windowControllerDidLoadNib:(NSWindowController *)windowController
    {
      ...
      [sourcesOutlineView expandAllNodes:nil];
    }

    - (BOOL)configurePersistentStoreCoordinatorForURL:(NSURL *)url
    ofType:(NSString *)fileType error:(NSError **)error
    {
      ...
      [sourcesOutlineView expandAllNodes:nil];
    }

    The expansion doesn't occur. I'm guessing this is because the outline
    view hasn't by this time been associated to its NSTreeController data
    source.

    Does anyone know where I could place the -expandAllNodes call so that
    it will be triggered after the nib has been loaded and all the data
    sources hooked up?

    Thanks in advance!
    Chris
    --
    <chris...>
    www.chrisblunt.com
  • [Putting this back on the coca-dev thread on the chance it might help
    somebody else; I get a lot of my answers in the archives...]

    On 10/23/07, Chris Blunt <chris...> wrote:
    >
    > Hi Doug,
    >
    > Thanks for your email. I'm not sure why, but my windowDidLoad method
    > is not firing. My MyDocument.h is a NSPersistentDocument and I've
    > connected it as the window's delegate, but no luck.
    >
    > Chris
    >

    Chris,

    Forgive me if these sound too obvious, but...

    Note that windowDidLoad is a method of NSWindowController, not a NSWindow
    delegate method.

    You'll need to subclass NSWindowController and override windowDidLoad, then
    ensure that your subclass is instantiated to load the nib.  It may be
    necessary to ensure that your nib file specifies the class of the "File's
    Owner" to be your NSWindowController subclass.

    I hope this helps.

    Doug K;
  • On Oct 23, 2007, at 12:07 PM, Doug Knowles wrote:

    > You'll need to subclass NSWindowController and override
    > windowDidLoad, then
    > ensure that your subclass is instantiated to load the nib.  It may be
    > necessary to ensure that your nib file specifies the class of the
    > "File's
    > Owner" to be your NSWindowController subclass.

    Why not just override the NSDocument windowControllerDidLoadNib:
    method in your NSDocument subclass and then use a delayed perform

    [theAppropriateTarget performSelector:@selector(expandMyNodes:)
    withObject:theAppropriateObject :0.0f];
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today