将distinctUnionOfObjects与NSArrayController和NSTableView一起使用

发布于 2024-11-17 09:08:50 字数 778 浏览 1 评论 0原文

我在过滤 NSArrayController 的内容并将其绑定到 NSTableView 的列时遇到问题。

事实上,我有一个表格,可以用它为我们的客户生成账单。为此,我有一个名为 Customer 的数组,我可以在那里收集每个客户的信息。

现在,我想向所有客户展示使用 NSTableView,当然我需要它不重复。 我知道我可以使用 @distinctUnionOfObjects 来创建唯一的客户数组,但它在 Interface Builder 的 Binding Inspector 菜单中不起作用。 当我使用控制器密钥:arrangedObjects 和模型密钥路径:@distinctUnionOfObjects.customerName 时,我收到一条错误,告诉我该实体不符合 KVC!

2011-06-28 00:22:03.212 FinancingPro[459:903] [<NSManagedObject 0x10053e1a0> valueForUndefinedKey:]: the entity Customer is not key value coding-compliant for the key "@distinctUnionOfObjects".

也许 distinctUnionOfObjects 不是正确的方法!

如何拥有具有唯一参数的 NSTableView

I'm having problem filtering an NSArrayController's content and binding it to the columns of an NSTableView.

In fact, I have a form that I use it to generate bills for our customers. To do this I have an array called Customer and I can collect each customer's information there.

Now, I want to show all our customers using an NSTableView and of course I need it to be duplicate-free.
I know I can use @distinctUnionOfObjects to create an unique array of customers, but it didn't work in Interface Builder's Binding Inspector menu.
When I use the Controller Key: arrangedObjects and Model Key Path: @distinctUnionOfObjects.customerName, I receive an Error telling me the Entity is not KVC compliant !!!

2011-06-28 00:22:03.212 FinancingPro[459:903] [<NSManagedObject 0x10053e1a0> valueForUndefinedKey:]: the entity Customer is not key value coding-compliant for the key "@distinctUnionOfObjects".

Maybe distinctUnionOfObjects is not the right way!

How can I have an NSTableView with unique parameters?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喜爱皱眉﹌ 2024-11-24 09:08:50

当我使用控制器密钥:arrangedObjects 和模型密钥路径:@distinctUnionOfObjects.customerName 时,我收到一条错误消息,告诉我该实体不符合 KVC !!!

2011-06-28 00:22:03.212 FinancingPro[459:903] [ valueForUndefinedKey:]:实体 Customer 不符合键“@distinctUnionOfObjects”的键值编码。

您已绑定到模型对象,而不是数组控制器。 arrangedObjects 是数组控制器的属性,而 @distinctUnionOfObjects 是仅数组和集合支持的特殊键,因此您需要绑定到数组控制器。

请注意,您的 @distinctUnionOfObjects 过滤器仅适用于该列,不适用于其他列。因此,您只是过滤客户的姓名,而不是客户本身。这很可能是错误的;您仍然可以在模型中拥有多个具有相同名称的客户,并且当您这样做时,表视图将翻转(因为您给了它多列不同长度的列)或显示实际上是垃圾的内容(错误的名称,因为它们相对于其他列向上移动)。

此外,假设您有一个仅包含名称列(例如源列表)的表视图,并且您对其应用了此过滤。然后,当您有重复的客户时,应用程序将只显示其中一位,而且是随机的。如果用户删除该客户,另一个(或其他客户之一)将会出现;这将显示为删除失败(“我删除了约翰·史密斯,但约翰·史密斯仍然出现在列表中!”)。

如果您打算禁止多个客户同名,请在使用 键值验证,并在表格视图中去掉这个输出限制。如果不知何故,您的用户在其数据库中获得多个具有相同名称的用户,您不希望您的应用程序变得疯狂。

您需要防止输入重复,而不是输出重复。

When I use the Controller Key: arrangedObjects and Model Key Path: @distinctUnionOfObjects.customerName, I receive an Error telling me the Entity is not KVC compliant !!!

2011-06-28 00:22:03.212 FinancingPro[459:903] [<NSManagedObject 0x10053e1a0> valueForUndefinedKey:]: the entity Customer is not key value coding-compliant for the key "@distinctUnionOfObjects".

You've bound to your model object, not an array controller. arrangedObjects is a property of an array controller, and @distinctUnionOfObjects is a special key only supported by arrays and sets, so you need to bind to your array controller.

Note that your @distinctUnionOfObjects filter will only apply to that column, not other columns. Thus, you are only filtering the customers' names, not the customers themselves. This is very probably wrong; you'll still be able to have multiple customers with the same name in the model, and when you do, the table view will either flip out (because you've given it multiple columns of differing lengths) or show what is effectively garbage (wrong names because they're shifted up relative to the other columns).

Furthermore, let's say you have a table view with only a name column, such as a source list, and you apply this filtering to it. Then, when you have duplicate customers, the app will only show one of them, and it will be a random one. If the user deletes that customer, the other (or one of the others) will show up; this will appear as if the deletion failed (“I deleted John Smith, but John Smith still appears in the list!”).

If you intend to disallow multiple customers with the same name, do that when customers are entered or changed using Key-Value Validation, and remove this output restriction in the table view. If, somehow, your user gets multiple users in their database with the same name, you don't want your application to go insane.

You need to prevent duplicates in input, not output.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文