How do you create a text label, how many rows are in the table

I am using Core Data and I want the text label to display the number of rows in the table, what code do I need to enter into the class file to do this?

+1


source to share


2 answers


Assuming the NSTableView columns are bound to the NSArrayController, you can bind the value of the NSTextField label to the array controller using the "builtObjects" controller key and the key path @count

. If you want to bind a text field to something like "x rows" where x is the number of rows, you must bind "Display Pattern Value1" to the same (ordered objects. @Count) and use "% {value1} @rows" as a display template.



+2


source


Set up the fetch query in the context of the managed entity as usual and invoke countForFetchRequest:

. Don't forget to subscribe NSManagedObjectContextObjectsDidChangeNotification

so you can update it when objects have been added or removed!



+2


source







All Articles