Binding radio buttons to user defaults

I have a simple prefs pane in my AppleScriptObjC project that contains an NSMatrix of four radio buttons. I have bound each button cell value to an item in the user defaults and I expected that when the radio buttons were clicked on that the four items in the user defaults would take on the value of the radio buttons. This does not happen.

On start up the app registers the four user defaults as

item1 = false
item2 = true
item3 = false
item4 = false

The radio buttons reflect this with button two being selected.

If I click on button1 then button3 then button4 I expected the four user default items to be

item1 = false
item2 = false
item3 = false
item4 = true

but when I look at the prefs plist file they are in fact all set to true and on restarting the app all of the radio buttons are selected

Obviously I am missing something here with the bindings. Can anybody enlighten me on this?

Is there some reason you need to bind the individual cells rather than the selected index of the matrix?

Hi Shane

My thinking was as follows. As each cell has a boolean value and the user default items were also boolean values it would be simply a matter of binding them. Obviously I was incorrect.

I can understand binding to selected index or selected tag where there is a single variable having a different value depending on the selected button but fail to see how I could use these where I have four independent variables each dependant on the state of one of the buttons

Perhaps I need to look at my data structures again but I really thought it would be simple to achieve these bindings.

Jim Graham

I’m surprised it doesn’t work as you hoped, too – I’m just thinking in terms of a workaround.

(I guess clicking on a cell is KVO compliant, but a cell being unhighlighted by the matrix is not.)

That would appear to be the case which I find really odd. The scenario I have described must occur often and is an ideal case for radio buttons. I will have a search on the net to see if I can find some other references.


You say you’re binding them to user defaults, but you also refer to variables. How are the two connected?

My error they are bound to user default entries

In that case I can’t see why binding the matrix instead is a problem. Or are other items also bound to the same defaults?

Yes you are right, I will stop railing against the flow and re-write that section to accommodate binding to the selected index of the matrix. I’m getting too old for this game, I want everything to be the way I want it :slight_smile:

Thanks for the interest and help.

Jim Graham