开发者

how to get count of records and aggregate of values via NSArrayController and cocoa bindings

开发者 https://www.devze.com 2023-01-05 14:33 出处:网络
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

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:

  1. Allowing user to insert, edit, modify numbers in each row in table.
  2. Displaying count of records entered in a text field.
  3. 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:

  1. Used @count bound to the arrayController's "arrangedObjects"
  2. 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

0

精彩评论

暂无评论...
验证码 换一张
取 消