1
votes

I've created a small test project to play with NSOutlineView before using it in one of my projects. I'm successful in displaying a list of items with children using a NSTreeController who's content is bound to an Array.

Bindings on my NSTreeConroller

Now while I created this object it took me ages to realize that my array contents would only show up if i created them in my init method: - (id)init { self = [super init];

if (self) {
    results = [NSMutableArray new];

    NSMutableArray *collection = [[NSMutableArray alloc] init];

        // Insert code here to initialize your application
    NSMutableDictionary *aDict = [[NSMutableDictionary alloc] init];
    [aDict setValue:@"Activities" forKey:@"name"];

    NSMutableArray *anArray = [NSMutableArray new];

    for (int i; i<=3 ; i++) {
        NSMutableDictionary *dict = [NSMutableDictionary new];
        [dict setValue:[NSString stringWithFormat:@"Activity %d", i] forKeyPath:@"name"];
        [anArray addObject:dict];
    }

    results = collection;

}

return self;
}

If I put the same code in applicationDidFinishLaunching it wouldn't show the items.

I'm facing the same issue now when trying to add items to the view. My understanding of using the NSTreeController is that it handles the content similar to what NSArrayController does for a NSTableView (OutlineView being a subclass and all). However, whenever I use a KV compliant method to add items to the array the items do not show up in my view.

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSMutableDictionary *cDict = [[NSMutableDictionary alloc] init];
[cDict setValue:@"Calls" forKey:@"name"];
[results addObject:cDict];
[outlineView reloadData];
}

I've also tried calling reloadData on the outlineview after adding an object, but that doesn't seem to be called. What am I missing?

Here's a link to my project: https://dl.dropboxusercontent.com/u/5057512/Outline.zip

1

1 Answers

1
votes

After finding this answer: Correct way to get rearrangeObjects sent to an NSTreeController after changes to nodes in the tree?

It turns out that NSTreeController reacts to performSelector:@selector(rearrangeObjects) withObject:afterDelay: and calling this after adding the objects lets the new objects appear.