Reputation: 15510
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?
Upvotes: 1
Views: 403
Reputation: 107754
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.
Upvotes: 2
Reputation: 40517
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!
Upvotes: 2