[英]Overriding keyDown: in an NSTableView category disables arrow key handling
I have an NSTableView
and I have some issues with its default behavior. 我有一个NSTableView
,它的默认行为有一些问题。
If I've overridden the keyDown:
method in a category as follows: 如果我重写了类别中的keyDown:
方法,如下所示:
- (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. 在NSTableView的类别中。
In a category of NSTableView
, super
refers to NSTableView
's superclass ( NSControl
), not to NSTableView
as it would in a subclass . 在NSTableView
的类别中, super
是指NSTableView
的超类( NSControl
),而不是像子 NSTableView
那样是指NSTableView
。 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. 您NSControl
事件传递给keyDown:
的NSControl
版本,该版本对表视图一无所知,并且无法以所需方式处理箭头键。
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. cf. Using Super in an Objective C Category? 在目标C类别中使用超级吗? and Is calling super in a category the same as calling it in a subclass? 并且在类别中调用super是否与在子类中调用super相同?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.