how to get count of records and aggregate of values via NSArrayController and cocoa bindings
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
this problem is resolved now I did following things to resolve it:
- Used @count bound to the arrayController's "arrangedObjects"
- For the sum part: i. Binded value property of text field to transactions array controller. ii. Set controller key as - arrangedObjects iii. Set model key path as - @sum.amount
cheers.... Miraaj
精彩评论