Re: NSMatrix -allowsEmptySelection (but doesn't) -- (kind of solved)
Re: NSMatrix -allowsEmptySelection (but doesn't) -- (kind of solved)
- Subject: Re: NSMatrix -allowsEmptySelection (but doesn't) -- (kind of solved)
- From: Jeremy Dronfield <email@hidden>
- Date: Fri, 26 Nov 2004 16:25:18 +0000
On 26 Nov 2004, at 2:23 pm, Jeremy Dronfield wrote:
Have I misunderstood the documentation on this? According to the
NSMatrix docs:
"setAllowsEmptySelection: has an effect only if the selection mode is
NSRadioModeMatrix. It lets you choose whether, in a group of radio
buttons, it’s allowed for none of them to be on. For example, say the
user clicks on the one radio button in a matrix that’s on. If
allowsEmptySelection is YES, that button turns off and none of the
radio buttons is on."
I have custom matrix with mode set to NSRadioModeMatrix and
allowsEmptySelection returning YES which doesn't behave as advertised.
When it first loads, it has no cells selected (which is correct), but
once a cell has been selected, it can only be unselected by selecting
a different one, not by clicking on it again.
Tracking the cell's -state during a click shows that it switches to
NSOffState on mouse down, then back to NSOnState on mouse up.
Have I missed something, or is the documentation misleading (or plain
wrong)?
Replying to myself... I've got the behaviour I wanted by overriding
-mouseDown: in my matrix subclass and doing this:
- (void)mouseDown:(NSEvent *)event
{
int row, column;
NSPoint clickPoint = [event locationInWindow];
clickPoint = [self convertPoint:clickPoint fromView:nil];
[self getRow:&row column:&column forPoint:clickPoint];
id clickedCell = [self cellAtRow:row column:column];
if (clickedCell == [self selectedCell])
[self deselectSelectedCell];
else
[self selectCellAtRow:row column:column];
}
However, my impression from the documentation is that this shouldn't be
necessary. Shouldn't an NSRadioModeMatrix matrix which allows empty
selection just handle this automatically? (Note that the above method
makes the matrix behave as a radio matrix even without its mode set to
NSRadioModeMatrix. To take advantage of the thrilling possibilities of
NSRadioModeMatrix, I can replace the last line of code with [super
mouseDown:event].)
Regards,
Jeremy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden