CocoaDev

Edit AllPages

I have a problem with NSArrayController : I have a NSTableView and a NSArrayController that is bound to. There are, for example, 5 values for each NSManagedObject of the NSArrayController. But what I want is to have a 6th column, calculated ,and that depends on the other Objects…

To try to be clear, each object is a financial transaction, with an amount, and I want my NSTableView to print a balance for each transaction, indicating the account balance up to this particular transaction. That is : that balance value depends on the previous transaction and the current transaction amount.

I’ve tried to add a instance variable in the Transaction Class :

But from the balance method I cannot reach the previous Transaction Object. So I think what I want should be implemented in a NSArrayController subclass.

Does anyone have an idea about it ?


Using a controller and bindings for some columns in your table does not prevent you from using a traditional data source for your other columns.

I’d recommend that you create a data source object that has a pointer to the array controller, and calculate your value on-demand inside tableView:objectValueForTableColumn:row: by examining the array controller’s arrangedObjects.


Many thanks, that worked. I linked a delegate to my tableview, and coded the following method in it :