Re: radio buttons
Re: radio buttons
- Subject: Re: radio buttons
- From: "John C. Randolph" <email@hidden>
- Date: Sat, 29 Dec 2001 04:01:58 -0800
It looks like you're correct that the matrix sends its action
before correcting the state of all of the cells. I just tried
this myself but instead of polling the cells, I sent [sender
selectedCell], which gave me the correct cell each time.
The sender in each case was the Matrix itself, not any of the
cells (which is what I would expect when the matrix is in radio
button mode)
(gdb) po [sender cells]
(
<NSButtonCell: 0x15afd0>,
<NSButtonCell: 0x238730>,
<NSButtonCell: 0x2388a0>,
<NSButtonCell: 0x2394c0>
)
this is what I got when I hit the first cell:
(gdb) po [sender selectedCell]
<NSButtonCell: 0x15afd0>
and this is what I got when I hit the last cell:
(gdb) po [sender selectedCell]
<NSButtonCell: 0x2394c0>
I also checked whether the first cell was still on, which it was:
(gdb) p (id) [sender cellAtRow:0 column:0]
$1 = (objc_object *) 0x15afd0
(gdb) p (bool) [$1 state]
$2 = 1
and found that the state of the last cell was also on:
(gdb) p (id) [sender selectedCell]
$3 = (objc_object *) 0x2394c0
(gdb) p (bool) [$3 state]
$4 = 1
There are at least two easy workarounds, though. The first is
to use the tag values like so:
myState = [[sender selectedCell] tag];
(IB will assign default tags to cells in a radio button matrix,
but you can set your own if you like.)
and the other is to ask the sender for the selected row:
myState = [sender selectedRow];
Either way, you don't need to examine every cell in a loop.
-jcr
On Saturday, December 29, 2001, at 02:30 AM, Jody Fairchild wrote:
>
i seem to have discovered a situation where a multiple cells in a radio
>
group can return NSOnState at the same time. first i have to
>
say that i
>
can't believe that this is not due to something i'm doing
>
wrong, but it's
>
sufficiently weird that i'm asking the list.
>
>
i have a preferences window with a couple of radio groups. the radio
>
groups and a couple of other buttons are targeted (via ib) to a
>
method in
>
my prefs controller which is supposed to map the current state of the
>
controls to their matching settings in the app. this works
>
fine for the
>
checkboxes, but as i cycle through the cells for a radio group,
>
i find that
>
_more than one_ claims to be "on"! the following code:
>
>
NSLog(@"opchange_handler, inside radio section, count = %i\n",
>
[[sender cells] count]);
>
>
for (i = 0; i < [[sender cells] count]; i++)
>
{ if ([[sender cellAtRow:i column:0] state] == NSOnState)
>
{ NSLog(@"opchange_handler, inside radio section loop,
>
selected = %i\n",i);
>
// break;
>
}
>
}
>
>
(note the commented out for debugging purposes "break" above)
>
generates the
>
following output (slightly altered to fit here):
>
>
opchange_handler, inside radio section, count = 4
>
opchange_handler, inside radio section loop, selected = 0
>
opchange_handler, inside radio section loop, selected = 1
>
>
it seems that clicking one of the buttons in the radio group
>
(which is what
>
triggers the above code) sends the triggering event before (or
>
maybe during
>
the process of) changing the states of the buttons. like i
>
said, unless i'm
>
doing something really stupid, this seems like some kind of a
>
bug to me.
>
>
can someone point me to a clue as to what's going on here? if
>
you reply to the
>
list, please also cc <email@hidden>.
>
>
thanks,
>
-jf
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
>
>
[Objc retain];