Binding an NSTableColumn using Collection statements like @sum

Mac OS X. CoreData Application. An NSTableView managed by NSArrayController is associated with a managed object for a Country object. The essence of the country has the attribute “name” and the relation “many”, “branches”, to branches. The Branch object has the attribute "sales" (NSNumber).

There are two NSTableColumns in NSTableView. The first shows the name of the country. The second should show the total sales for this country in all its branches.

The first column value is bound to NSArrayController objects organized by the model key path to the name. There are no problems.

The second value of the column is tied to NSArrayController objects organized using the "branch. @ Sum.sales" model key path. This does not work. I get an error: "addObserver: forKeyPath: options: context:] is not supported. Key path: @ sum.sales"

If instead, I add the totalSales method to my Country class, and the method will be implemented as follows:

- (NSNumber *)totalSales { return [[self branches] valueForKeyPath:@"@sum.sales"]; } 

and then bind the column to 'totalSales', it works fine. My understanding of the Collection Operators documentation is that it should be the same as just binding to "branches". @ Sum.sales. "I don’t understand why the latter does not work. Any ideas? I saw similar questions in this and other forums, but I don’t see any explanations or solutions yet.

0
source share
1 answer

I do not know if this is still a subject for you, but it certainly needs an answer.

The second column value must be bound to the NSArrayController in the same way as the first. I don’t know why you did it differently and what you really wanted to achieve.

Your first task was to bind the columns of the table to the columns of the array, and this works the same for all columns and types.

The second task is to get the sum of some NSTableColumn bound to a specific other object, for example, NSTextfield. And this is done as follows:

  [totalCountField bind: @"value" toObject: arrayController withKeyPath:@" arrangedObjects.@sum.price " options:nil]; 
0
source

Source: https://habr.com/ru/post/1399029/


All Articles