views:

54

answers:

2

First of all I'm new to cocoa development so I suppose I'm probably trying to do this the wrong way, but here goes: I have a NSOutlineView which loads the data from a NSOutlineViewDataSource imnplementation. I want all the items to be expanded after they are loaded, but i can't seem to find an event fired when the data has finished loading, so I can send a [outlineView expandItem:nil expandChildren: YES] to it. I looked into the NSOutlineViewDelegate protocol but I was unable to find a sutable place for this call. What would be the best approach for this problem ?

+1  A: 

Here's how I normally handle this. I like to show my main window myself rather than letting it happen automatically. This allows me to make sure all of my interface items are setup how I want before I show the user the window. It seems you could do this too. So first I uncheck "Visible at launch" in interface builder for the window. Then in my application's delegate class I use this method which is a deleate method of NSApplication:

  • (void)applicationDidFinishLaunching:(NSNotification *)aNotification

In there I setup my interface items because at that point I know everything is loaded. And then the last line of that method would be: [myWindow makeKeyAndOrderFront:self];. This way you know your window is perfect before your user sees the window. So I would try your method there.

regulus6633
thanks, but this isn't a solution for me since the outlineview is in a panel that opens when a user clicks a button, and the data seems to be loaded when the panel is showed, not when the application launches
matei
A: 

I found the answer. It seems that implementing the delegate method -(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item will do the trick:


-(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
    [outlineView expandItem:item];
}
matei
later edit: this is not a good answer, it seems to screw up on the last items in the outlineview and not show them so any help would be appreciated
matei