简体   繁体   中英

Overriding keyDown: in an NSTableView category disables arrow key handling

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?

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM