I have NSRadioModeMatrix with 3 cells. - (IBAction) EnableProxy:(id)inSender is connected to NSRadioModeMatrix
- (IBAction) EnableProxy:(id)sender
{
if ([[sender selectedCell] tag]==2)
{
/*(gdb) p (int)[[inSender selectedCell] tag]
$1 = 2*/
if (condition) {
// select cell with tag 0
[sender selectCellAtRow:0 column:0]; // This is not working
}
/*(gdb) p (int)[[inSender selectedCell] tag]
$2 = 1*/
}
}// selection is not visible
When condition is true. selection is going back to tag 2(old selected cell).Sample project.
To be honest, this is the intended behavior, and for good reason.
Given the above UI, if a user clicks on
C, they expectCto become selected. If instead, a user clicks onCandAbecomes selected, you have a confused (and potentially frustrated) user. Indeed, implementing this type of behavior violates the OS X Human Interface Guidelines for Radio Buttons.That said, I'll move on to how you can implement the behavior you want. Basically, the reason why when you select
C, the immediate call to selectAdoesn't seem to succeed is that, technically speaking,Cis still in the process of being selected. In other words, a simplified timeline of the events would look like the following:EnableProxy:method calledACis finally completely selectedIn order to achieve the results you want, instead of immediately telling the matrix to select
A, you'll need to "queue" the request up like the following code does:By using
[self performSelector:withObject:afterDelay:], you basically say "call this method as soon as possible". Doing so letsCbe fully selected before that method is called, which allows the results you want. In other words, the timeline of events would look like this:EnableProxy:method calledCis finally completely selectedselectFirstMatrixRowmethod calledA