views:

135

answers:

2

I am using Core Data and want a Text Label to display how many rows there are in the table, what code would I need to enter in the class file's to do this?

+2  A: 

Set up a fetch request on your managed object context like you normally would, and call countForFetchRequest:. Don't forget to subscribe to NSManagedObjectContextObjectsDidChangeNotification so you can update it when objects are added or removed!

Marc Charbonneau
Can you give me some example code?
Joshua
Example Code, if thats possible please?
Joshua
Joshua: If you don't know how to set up a fetch request or you don't know how to register as a local notification observer, read the documentation: http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/ and http://developer.apple.com/documentation/Cocoa/Conceptual/Notifications/
Peter Hosey
+1  A: 

Assuming your NSTableView's columns are bound to an NSArrayController, you can bind the value of the NSTextField label to your array controller's with controller key "arrangedObjects" and with a key path of @count. If you want to bind the text field to something like "x rows" where x is the number of rows, you would bind the "Display Pattern Value1" to the same (arrangedObjects.@count) and use "%{value1}@ rows" as the Display Pattern.

Barry Wark