开发者

NSTreeController does not respond to reloadData

开发者 https://www.devze.com 2023-04-05 12:26 出处:网络
I have a NSTreeController with bindings to a class. NSOutlineView dirTree binds to the NSTreeController

I have a NSTreeController with bindings to a class.

NSOutlineView dirTree binds to the NSTreeController

In particular Outline View Content binds to arrangedObjects

This appears to work well, but I am at my wits end to figure out why it does not respond to reloadData.

The NSTreeController Key paths are:-

Children    subDirectories
Count       numberOfSubDirs

These are listed below; numberOfSubDirs returns a simple count of subDirectories (with an added diagnostic display).

- (NSArray *)subDirectories {
    if (subDirectories == nil) {
        [self loadSubDirectories];
    }
    return subDirectories;
}

- (NSInteger)numberOfSubDirs {
    NSArray *tmp = [self subDirectories];
    NSLog(@"numberOfSubDirs %@ %d", [self relativePath], [tmp count]);
    return [tmp count];
}

If I call a refresh function which updates the data then calls [dirTree reloadData]; I get the following output:-

Reload Data
numberOfSubDirs Shared 7
numberOfSubDirs Adobe 1
numberOfSubDirs bZTree2 0
numberOfSubDirs Ian Documents 25
numberOfSubDirs Library 1
numberOfSubDirs NET 1
numberOfSubDirs TSA 12
numberOfSubDirs Wacom 1

If I delete a directory (externally in Finder) an开发者_如何学JAVAd call the refresh function I get the following output:-

Reload Data
numberOfSubDirs Shared 6
numberOfSubDirs Adobe 1
numberOfSubDirs bZTree2 0
numberOfSubDirs Ian Documents 25
numberOfSubDirs Library 1
numberOfSubDirs NET 1
numberOfSubDirs TSA 12
numberOfSubDirs Wacom 1

NSTreeController calls numberOfSubDirs on the parent "Shared", and is correctly told it now has 6 subdirectories.

However it then queries 7 subdirectories, including the deleted item "bZTree2", and does not refresh the display to show only the 6 which exist.


NSTreeController does not respond to -reloadData because it doesn't implement that method. You will get both a runtime exception and a compiler warning if you try to call it on an NSTreeController instance.

NSOutlineView responds to -reloadData, but it won't do anything unless the NSOutlineView uses a data source. If you are using NSTreeController it won't do anything at all.

Since you seem to be creating a file system view, I highly recommend you go via the data source route rather than using NSTreeController, it will save you a lot of trouble.

Apple has some documentation and sample code for doing this also.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号