I have an NSArrayController with a table view, and the associated bindings.
The table has an add and remove button, I used Shane’s book to set this up.
My “Remove” button is has it’s availability bound to the array controllers “canRemove” controller key.
I’d like to do something for the “Add” button, as I need to limit the size of the table. RIght now I ignore the problem, and later pop up a dialog saying to many entries where added… I’d like to just disable the button if no more slots are open in the table.
I have a function/method in apple script that returns true/false if the table is already full, but can’t seem to figure out how to bind this to the app delegate.
Thinking about it, it may not work. Plan B is to define your own add: and remove: handlers that call those of the array controller, but also do a count of the entries, and use that count to set a boolean property you bind to the enabled property of the Add button.
you have to implement the key value observing method keyPathsForValuesAffecting
For example
property itemCounter : 0
on keyPathsForValuesAffectingEnableAdd()
return current application's NSSet's setWithObject:"itemCounter"
end keyPathsForValuesAffectingEnableAdd
on enableAdd()
return my itemCounter < 10
end enableAdd