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
2009-05-04 22:15:14
Can you give me some example code?
Joshua
2009-05-05 05:51:55
Example Code, if thats possible please?
Joshua
2009-05-07 05:42:44
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
2009-05-23 16:31:11
+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
2009-05-04 22:30:39