Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top