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

sebastijan

macrumors member
Original poster
May 22, 2005
62
2
London, UK
OK. First I use CoreData and have one question. How can I sum numbers in NSTableView and show them in NSTextField? Like in this pic:

picture2qc7m.png


P.S.: Sorry for my bad English.
 
Unless you're doing anything else with the data then Core Data is way overkill for what you're doing. All you need is an array and perhaps use cocoa bindings (ie an NSArrayController) to handle the boilerplate code.
 
There's not much to see in terms of code as basically the only code is the setting up of an NSMutableArray and a small method for summing the contents. All the cocoa bindings stuff is done graphically in interface builder. There's quite a few cocoa bindings examples knocking around on the web (like this one).
 
There's not much to see in terms of code as basically the only code is the setting up of an NSMutableArray and a small method for summing the contents. All the cocoa bindings stuff is done graphically in interface builder. There's quite a few cocoa bindings examples knocking around on the web (like this one).

tnx caveman_uk.

But can i get some example - source or xcode proj - for this? please.

I know how to use table in coreData and some bindings stuff... but i dont know how to sum numbers in table and show them in TextField.
 
See the attached. This does it without using CoreData as there is no need for that here. The summing is done entirely in the bindings system ( :cool: ). Note that the sum only recalculates when you add or remove an item from the array. I'm sure you can sort this but I'm not about to worry about how to do that now.
 

Attachments

  • Sum.zip
    42.3 KB · Views: 115
Code:
+ (void)initialize {
    [MyNumber setKeys:
        [NSArray arrayWithObjects:@"string", nil]
        triggerChangeNotificationsForDependentKey:@"@sum.intValue"];
}

why doesn't this work?
 
Because @sum is not part of the key within this object. The dependent key in the object is simply intValue. The @sum is a directive to sum across the collection of these objects.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.