以编程方式向NSOutlineView添加列时的性能问题

时间:2016-04-22 10:37:35

标签: objective-c cocoa nstableview cocoa-bindings nsoutlineview

在我的应用程序中,我想使用大纲视图来显示不同类型对象的属性。由于从外部数据库检索属性,因此在编译时不知道它们;因此,我需要动态添加列。

我已经设置了Cocoa绑定来显示值,但是我遇到了一些非常严重的性能问题。当我在Interface Builder中使用绑定定义列时,性能非常好。但是当我添加列并以编程方式绑定到相同的值时,应用程序在滚动时会挂起几秒钟,使用100%的CPU。

数据模型如下:
Core Data Object Model Xcode

每个dynamicAttributes属性都包含一个具有以下结构的NSDictionary: dynamic attributes dictionary structure

我使用以下代码添加列:

for (NSString *key in instDynAttsDict) {

    NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:key];
    column.title = key;
    [self.instancesOutlineView addTableColumn:column];

    NSString *keyPath = [NSString stringWithFormat:@"arrangedObjects.dynamicAttributes.%@.value", key];
    [column bind:NSValueBinding toObject:self.instancesTreeController withKeyPath:keyPath options:nil];

}

我在这里发布了一个测试项目,其中包含一些示例数据:https://drive.google.com/open?id=0B5lGn_3atgSeNWVUX3l6cmVxUUE
您需要将数据库OSXCoreDataObjC.storedata复制到Application Support目录中。 (特定路径在应用启动时注销。)

0 个答案:

没有答案
相关问题