keyUp事件听到?:覆盖NSView方法 [英] keyUp event heard?: Overridden NSView method

查看:157
本文介绍了keyUp事件听到?:覆盖NSView方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UPDATED:我现在将NSView keyUp方法从NSView子类设置替换为第一个响应者,如下所示,但仍然没有看到它被调用的证据。

UPDATED: I'm now overriding the NSView keyUp method from a NSView subclass set to first responder like below, but am still not seeing evidence that it is being called.

@implementation svsView

- (BOOL)acceptsFirstResponder {
    return YES;
}

- (void)keyUp:(NSEvent *)event {
  //--do key up stuff--
  NSLog(@"key up'd!");
}

@end

- ORIGINAL POST -
我是Cocoa和Obj-C的新手,我试图做一个(void)keyUp:从我的控制器类(其本身是NSController类型)的实现中。我不知道这是否是正确的地方。我有一系列类似的按钮,每个按钮都设置为一个唯一的键等效(IB按钮属性),每个调用my(IBAction)keyInput方法,然后将每个键的标识传递到另一个对象。这个运行很好,但是我也想跟踪每个密钥是否被发布。

--ORIGINAL POST-- I'm new to Cocoa and Obj-C and am trying to do a (void)keyUp: from within the implementation of my controller class (which itself is of type NSController). I'm not sure if this is the right place to put it, though. I have a series of like buttons each set to a unique key equivalent (IB button attribute) and each calls my (IBAction)keyInput method which then passes the identity of each key onto another object. This runs just fine, but I also want to track when each key is released.

- ORIGINAL [bad] EXAMPLE -

--ORIGINAL [bad] EXAMPLE--

@implementation svsController

//init
//IBActions

- (IBAction)keyInput:(id)sender {
  //--do key down stuff--
}

- (void)keyUp:(NSEvent *)event {
  //--do key up stuff--
}

@end

一旦失败,我也尝试使用keyUp作为IBAction(而不是void),就像用户定义的keyInput一样,并将其连接到Interface Builder中的相应按钮,但是keyUp仅在键被关闭时被调用而不是在释放时。 (我有这种想法会发生)。

Upon fail, I also tried the keyUp as an IBAction (instead of void), like the user-defined keyInput is, and hooked it up to the appropriate buttons in Interface Builder, but then keyUp was only called when the keys were down and not when released. (Which I kind of figured would happen.)

赦免我的noobery,但是我应该把这个方法放在另一个班上,或者做不同的事情吗?不管怎样,我需要它能够访问控制器类所拥有的对象。

Pardon my noobery, but should I be putting this method in another class or doing something differently? Wherever it is, though, I need it be able to access objects owned by the controller class.

感谢您有任何见解。

推荐答案

哇!我想我已经钉了我只需要使用NSView / NSWindow引用IB中的类实例化我的子类。实际上并没有在UI中创建它的一个实例。过去几个小时下来的螃蟹!不,我一路上学到了一两件事。 ;)

Wow! I think I've nailed it. I just needed to instantiate my subclass with a NSView/NSWindow reference to the class in IB. Wasn't actually creating an instance of it in the UI. The past several hours down the crapper! Sans that I learned a thing or two along the way. ;)

这篇关于keyUp事件听到?:覆盖NSView方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆