Hi
How can i collect the statut of each Radio Button in a list.
I made a NSMatrix which is in tracking mode (mean possible to select 1 or more button)
The property is testMatrix
i want to collect the statut of each cell in a list (button1 , button2, .)
Here my code which is not working.
It give me the last button click (on or off)
script NSMatrixAppDelegate
property parent : class "NSObject"
property testMatrix : missing value
on monButton_(sender)
set monResultat to ""
set monResultat to testMatrix's selectedCell()'s |title|() as list
log "mon resultat " & monResultat
end monButton_
..
end script
You will probably need to use selectedCells() rather than selectedCell(), and then get the title of each one. You could try this, which might avoid a repeat loop:
set monResultat to testMatrix's selectedCells()'s valueForKey_("title") as list
I experimented with this problem using a matrix of radio buttons set to tracking mode. I tried Shane’s suggestion, and despite what the documentation says, selectedCells() only gives an array with one item that shows the last item clicked on whether that button is on or off. I was able to get a list of which buttons were selected by using a loop to go through the cells of the matrix and look at their state. Here is the code that worked for me:
on push_(sender)
set monResultat to {}
set matrixSize to testMatrix's numberOfRows()
repeat with counter from 0 to (matrixSize - 1)
set theCell to testMatrix's cellAtRow_column_(counter, 0)
set monResultat to monResultat & theCell's |state|()
end repeat
log monResultat
end push_
The matrix I used had 5 rows and 1 column. The result is an array with 1’s for buttons that are selected and 0’s for ones that are not.
According to the Apple Human Interface Guidelines, though, you really shouldn’t use radio buttons if you want to allow the user to select more than one item at a time. It would be better to use a matrix of check boxes.
I tried this, and it didn’t work – it does work if you use “state” instead of “tag” though.
When I first tried your method it worked, but so did replacing “tag” with “blah” or just “log testMatrix’s |cells|()”, and then even more bizarrely, I got rid of every statement in my method except “log monResultat” and that worked too! But when I tried to do some undoing, I got some errors and Xcode froze up. After a force quit and restart, none of the things I mentioned in this paragraph worked --I’m not sure what was going on here. It seems like the code wasn’t actually changing even though it looked like it on the screen.