无法处理NSButton子类中的任何事件

时间:2012-10-03 09:51:16

标签: objective-c

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

[parentView addSubview:button];

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

我尝试了google发现的任何示例,但我无法处理任何事件。我的意思是我试过这些:

在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

1 个答案:

答案 0 :(得分:0)

我假设你没有使用Interface Builder。

确保正确设置目标,操作和事件。这是pageControl的一个例子。

[pageControl addTarget:self
                action:@selector(pageTurning:)
      forControlEvents:UIControlEventValueChanged];
相关问题