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

Discussion in 'Mac Programming' started by Monaj, Jul 5, 2010.

  1. Monaj macrumors regular

    Joined:
    May 24, 2009
    #1
    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
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    Location:
    Brobdingnag
    #2
  3. Monaj thread starter macrumors regular

    Joined:
    May 24, 2009
    #3
    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
     

Share This Page