0

I have an NSTableView and I have some issues with its default behavior.

If I've overridden the keyDown: method in a category as follows:

- (void) keyDown:(NSEvent *)event {
    [super keyDown:event];
}

I can't change the row selection with the keyboard arrow keys anymore. Why is that?

jscs
  • 63,694
  • 13
  • 151
  • 195
aneuryzm
  • 63,052
  • 100
  • 273
  • 488
  • where do you override that method in your view controller ? –  Dec 19 '11 at 15:29
  • No, in a category of NSTableView. I haven't written the category, but the - (void) keyDown:(NSEvent *)event method is overridden there. – aneuryzm Dec 19 '11 at 15:43

1 Answers1

7

in a category of NSTableView.

In a category of NSTableView, super refers to NSTableView's superclass (NSControl), not to NSTableView as it would in a subclass. You're passing the event on to the NSControl version of keyDown:, which knows nothing about table views and can't handle the arrow keys the way you want.

If you override a method in a category, there's no way to call the original method. It's almost never a good idea to do this on framework classes (whose source is unavailable to you). Use a subclass.

Cf. Using Super in an Objective C Category? and Is calling super in a category the same as calling it in a subclass?

Community
  • 1
  • 1
jscs
  • 63,694
  • 13
  • 151
  • 195