Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expanding all items of a NSOutlineView that loads data from a data source

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 implementation. 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 suitable place for this call. What would be the best approach for this problem?

like image 631
matei Avatar asked Apr 13 '10 16:04

matei


2 Answers

Normally I like to do something like this inside form - awakeFromNib or any other startup callbacks

dispatch_async(dispatch_get_main_queue(), ^{
    [self.outlineView expandItem:root expandChildren:YES];
});

This will enqueue the execution block at the end of the current cycle in the runloop, thus, it will be executed after all initialization has taken place. There's no need to set any artificial delay.

like image 54
Merlevede Avatar answered Oct 25 '22 01:10

Merlevede


The best solution I've come up with is to write a method that expands the NSOutlineView after a delay of zero.

- (void)windowDidLoad
{
    [super windowDidLoad];
    [self performSelector:@selector(expandSourceList) withObject:nil afterDelay:0.0];
}

- (IBAction)expandSourceList
{
    [mSourceListView expandItem:nil expandChildren:YES];
}
like image 41
gerdemb Avatar answered Oct 25 '22 01:10

gerdemb