如何通过 NSArrayController 和 cocoa 绑定获取记录计数和值聚合
我正在尝试使用 NSArrayController 和可可绑定的简单应用程序。该应用程序包含 - 一个只有一列的表格,两个用于添加和删除记录的按钮“+、-”,两个用于显示输入记录数和这些记录总和的文本字段。
为了允许用户仅输入数字,我已将 NSNumberFormatter 分配给 NSTextField 单元格。
模型类:“Transaction”仅包含一个属性:“amount”。我使用 @property 和 @synthesize 来声明和定义其访问器方法。
总而言之,我想执行以下任务:
- 允许用户插入、编辑、修改表中每一行的数字。
- 显示在文本字段中输入的记录数。
- 显示在其他文本字段中输入的数字的聚合。
我能够获得第一分。通过可可绑定,但是当我尝试实现第二点和第三点时,它没有按预期工作。
我为第二和第三点做了以下事情。
对于第二点.... 1. 在文本字段的绑定首选项中。我将值绑定到数组控制器。 模型关键路径设置为@count.amount
2.将第三点的 ... 1. 在文本字段的绑定首选项中。我将值绑定到数组控制器。 2.将模型关键路径设置为@sum.amount
任何人都可以建议我哪里可能是错误的或其他方法来实现我的要求?
谢谢,
米拉杰
I am trying a simple application using NSArrayController and cocoa bindings. The application contains - a table with only one column, two buttons "+, -" to add and delete records, two text fields to show count of records entered and sum of these records.
To allow user to enter numbers only, I have assigned NSNumberFormatter to the NSTextField cell.
The model class: "Transaction" contains only one property: "amount". I have used @property and @synthesize to declare and define its accessor methods.
So in all, I want to perform following task:
- Allowing user to insert, edit, modify numbers in each row in table.
- Displaying count of records entered in a text field.
- Displaying aggregate of numbers entered in other text field.
I am able to achieve 1st pt. via cocoa bindings but when I tried to implement 2nd and 3rd pt., it is not working as intended.
I did following things for 2nd and 3rd pt.
for 2nd pt....
1. In binding preference of a text field. I am binding value to array controller.
2. Setting model key path as @count.amount
for 3rd pt....
1. In binding preference of a text field. I am binding value to array controller.
2. Setting model key path as @sum.amount
Can anyone suggest me where I may be wrong or some other way to achieve my requirements??
Thanks,
Miraaj
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题现在已经解决了,我做了以下事情来解决它:
欢呼...... Miraaj
this problem is resolved now I did following things to resolve it:
cheers.... Miraaj