利用收集运营商像@sum NSTableColumn结合 [英] NSTableColumn binding using Collection Operators like @sum

查看:217
本文介绍了利用收集运营商像@sum NSTableColumn结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mac OS X的应用程序CoreData。 NSTableView的由NSArrayController的控制必将为国家的实体管理对象上下文。国家实体有一个名称属性和一对多的关系,树枝,到分支实体。该科的实体有一个销售属性(一个NSNumber)。

Mac OS X. CoreData app. NSTableView controlled by NSArrayController bound to managed object context for the Country entity. The Country entity has a 'name' attribute and a to-many relationship, 'branches', to a Branch entity. The Branch entity has a 'sales' attribute (an NSNumber).

该NSTableView的有两个NSTableColumns。第一条显示国家的名字。第二个应显示总销售额在其所有分行的国家。

The NSTableView has two NSTableColumns. The first shows the name of the Country. The second should show the total sales for that Country across all its Branches.

第一列的值被绑定到NSArrayController的的arrangedObjects与'名称'的典范关键路径。这里没有问题。

The first column's value is bound to the NSArrayController's arrangedObjects with a model key path of 'name'. No problem there.

第二列的值被绑定到NSArrayController的的arrangedObjects与模型关键路径的分行。@ sum.sales。这是行不通的。我得到的错误信息:的addObserver:forKeyPath:选项:背景:]不支持关键路径:@ sum.sales

The second column's value is bound to the NSArrayController's arrangedObjects with a model key path of 'branches.@sum.sales'. This doesn't work. I get the error message: " addObserver:forKeyPath:options:context:] is not supported. Key path: @sum.sales"

如果,相反,我添加了一个totalSales的方法对我国类和方法的实现如下:

If, instead, I add a 'totalSales' method to my Country class and the method is implemented as follows:

- (NSNumber *)totalSales
{
    return [[self branches] valueForKeyPath:@"@sum.sales"];
}

和我然后绑定列totalSales它工作正常。我的集合运算符的文件的理解是,这应该是一样的简单结合的分行。@ sum.sales。我不明白为什么后面不起作用。有任何想法吗?我看到在这个和其他论坛类似的问题,但还没有看到一个解释或解决方案。

and I then bind the column to 'totalSales' it works fine. My understanding of the Collection Operators documentation is that this should be the same as simply binding to 'branches.@sum.sales'. I can't see why the latter doesn't work. Any ideas? I have seen similar questions in this and other forums, but have yet to see an explanation or solution.

推荐答案

我不知道这是不是还在为你的话题,但它肯定不会需要一个答案。

I don't know if this is still topic for you, but it surely does need an answer.

第二列的值应在完全SAM方式首先被绑定到NSArrayController的。我不知道你为什么做它不同,你想达到什么实际。

The second column's value should be bound to NSArrayController in exactly the sam way as first. I don't know why you made it differently and what actually you wanted to achieve.

您的第一项任务是表列绑定到数组列,这以同样的方式对所有列和类型。

Your first task was to bind table columns to array columns and this works the same way for all the columns and types.

第二任务是让结合到某些其他物体,像的NSTextField某些NSTableColumn的总和。这是这样做的:

Second task is to get sum of certain NSTableColumn bound to certain other object, like NSTextfield. And this is done like this:

    [totalCountField bind: @"value" toObject: arrayController
          withKeyPath:@"arrangedObjects.@sum.price" options:nil];

这篇关于利用收集运营商像@sum NSTableColumn结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆