Re: NSTableView ignoring arrow keys
Re: NSTableView ignoring arrow keys
- Subject: Re: NSTableView ignoring arrow keys
- From: Pete Yandell <email@hidden>
- Date: Tue, 17 Jun 2003 08:57:01 +1000
Actually the arrow keys don't work by default in NSTableView or
NSOutlineView, or at least they never have for me. I get around it by
subclassing NSTableView and adding:
- (void)keyDown:(NSEvent *)theEvent
{
[self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
}
- (void)moveUpByExtendingSelection:(BOOL)extendSelection
{
NSEnumerator* rowEnumerator = [self selectedRowEnumerator];
NSNumber* row;
int firstSelectedRow = -1;
if (row = [rowEnumerator nextObject])
firstSelectedRow = [row intValue];
if (firstSelectedRow != -1 && firstSelectedRow > 0) {
[self selectRow:firstSelectedRow - 1
byExtendingSelection:extendSelection];
}
}
- (void)moveDownByExtendingSelection:(BOOL)extendSelection
{
NSEnumerator* rowEnumerator = [self selectedRowEnumerator];
NSNumber* row;
int lastSelectedRow = -1;
while (row = [rowEnumerator nextObject])
lastSelectedRow = [row intValue];
if (lastSelectedRow != -1 && lastSelectedRow < [self
numberOfRows]-1) {
[self selectRow:lastSelectedRow + 1
byExtendingSelection:extendSelection];
}
}
- (void)moveUp:(id)sender
{
[self moveUpByExtendingSelection:NO];
}
- (void)moveUpAndModifySelection:(id)sender
{
[self moveUpByExtendingSelection:YES];
}
- (void)moveDown:(id)sender
{
[self moveDownByExtendingSelection:NO];
}
- (void)moveDownAndModifySelection:(id)sender
{
[self moveDownByExtendingSelection:YES];
}
I haven't done page up/page down handling, but you should be able to
work something out using this as a starting point. (Please shoot me the
code if you do...I wouldn't mind adding it to my apps.)
Pete Yandell
http://pete.yandell.com/
On Tuesday, June 17, 2003, at 02:33 AM, Chris Silverberg wrote:
>
Hi folks,
>
>
I have a somewhat complex window that contains a couple table views.
>
Last
>
night I noticed a bug in my application... they up/down arrow keys are
>
no
>
longer working to change the selection in my tables. Hitting up/down
>
does
>
nothing. page up/page down/home/end are also ignored. This didn't
>
used to
>
be the case and of course it's supposed to work by default. But I
>
can't see
>
anything that I'm doing that would cause this problem and I'm not even
>
sure
>
how best to debug it.
>
>
Does anyone have any suggestions as to what might cause NSTableView to
>
start
>
ignoring those keys?
>
>
thanks,
>
Chris
>
_______________________________________________
>
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.
_______________________________________________
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.