Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Monaj

macrumors regular
Original poster
May 24, 2009
193
0
Hi all,

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,

Monaj
 
solution found!

I have atlast found the solution of my problem... yeppy :)

I performed following steps, to obtain the sum of amount:

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.

To the count of amount, I did this:

Used @count bound to the arrayController's "arrangedObjects"

Cheers,

Monaj
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.