0

In OS X, I have an NSTableView with a row of NSButtonCells. These need to appear exactly like buttons of type NSRadioButton, but act more like an NSSwitchButton. In particular, if the state is NSOnState and I click it with the mouse, I need to toggle its state to off (yes I know this isn't standard behavior for radio buttons, but it's what I need to do.) If I use button cells of type NSSwitchButton, the behavior is exactly what I need; that is, the tableView calls my setObjectValueForTableColumn:row: gets called, where I can modify my data model appropriately. When I change the type to NSRadioButton however, neither that method, nor any other delegate method I can find, gets called when the cell state is On and it's clicked. Any ideas on the easiest way to do this?

Michael57
  • 85
  • 7
  • Is anybody going to know that they can click on the selected radio button again to deselect it? It might be better to just add a “None” button. – Peter Hosey Sep 10 '13 at 19:31

1 Answers1

0

You can use an NSToggleButton, show image only, and set the two images to a radio button de-selected and a radio button selected - provide those at both standard and retina resolutions (screen grab them from real radio buttons). Not perfect as it doesn't do the momentary highlight of a standard radio button, but close.

Note: An NSSwitchButton may work and highlight, but Apple state "Changing the images used for these buttons could lead to unpredictable results" - but IB will let you set the images...

CRD
  • 52,522
  • 5
  • 70
  • 86
  • Thanks, but I'd like to keep all the appearance, including momentary highlighting. I'd like to see if I can find a solution that involves using a real NSRadioButton and somehow get an event to be generated when it's clicked. I figured out how to do this now (awkwardly) by customizing my tableView to add some custom code to its mouseDown: method. I would rather be able to do it by just using a custom subclass of NSButtonCell, but I don't understand how it interacts with the tableView; that is, how does the tableView know not to call its datasource delegate when the radio button is clicked? – Michael57 Sep 11 '13 at 15:16