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?

2
  • where do you override that method in your view controller ?
    – user971401
    Dec 19, 2011 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, 2011 at 15:43

1 Answer 1

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.