【问题标题】:Can not handle any event in a NSButton subclass无法处理 NSButton 子类中的任何事件
【发布时间】:2012-09-24 05:34:15
【问题描述】:

我有我的 NSButton 子类,它作为子视图添加到 NSView 子类:

[parentView addSubview:button];

我所有的点击事件都传递给超级视图对象。

我尝试了谷歌找到的任何示例,但我无法处理任何事件。我的意思是我试过这些:

在 Button 的 init 方法中:

[self setTarget:self];

[self setAction:@selector(clicked)]; 

还有

[self setTarget:self];

[self setAction:@selector(methodWithNSEventParam:)]; 

也让他们发表评论。

永远不会“点击”。

覆盖以下方法(从未调用过)。

(void) mouseEntered:(NSEvent*)theEvent

(void) mouseExited:(NSEvent*)theEvent

(BOOL) mouseDownCanMoveWindow

(void) mouseDown:(NSEvent *)theEvent

(void) mouseUp:(NSEvent *)theEvent

(NSView*) hitTest:(NSPoint)aPoint

【问题讨论】:

    标签: objective-c


    【解决方案1】:

    我假设您没有使用 Interface Builder。

    确保您正确设置了目标、操作和事件。这是 pageControl 的示例。

    [pageControl addTarget:self
                    action:@selector(pageTurning:)
          forControlEvents:UIControlEventValueChanged];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-03
      • 2013-04-28
      • 2015-05-20
      • 1970-01-01
      相关资源
      最近更新 更多