13

I want to bind the enabled state of an NSButton to whether or not an NSArrayController has any selected items.

How do I do this?

Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131
Redwood
  • 66,744
  • 41
  • 126
  • 187

3 Answers3

22

Another option is to bind to selectedObjects.@count

Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131
sbooth
  • 16,646
  • 2
  • 55
  • 81
18

Generally speaking, binding the enabled binding to the canRemove property of the array controller should give you what you want. After all, you can only remove an object if there's one selected.

Alex
  • 26,829
  • 3
  • 55
  • 74
  • At a much later date than written, this does not work. – David Aug 17 '16 at 21:57
  • This works for me configuring the binding in IB in Xcode 8.2.1. Making sure that only the "Controller Key" is filled out with "canAdd" or "canRemove", there is no model key path or value transformer. – Andrew Sep 29 '17 at 23:11
3

This is the answer for IB:

enter image description here

If you need to setup the OR relationship with other NSArrayController (or other value), there is the section Enabled 2 , and so on. So, in my case, i have:

enter image description here

CheshireKat
  • 463
  • 3
  • 9