cancelOperation not called in NSView subclass

1k Views Asked by At

cancelOperation: is not being called in my bare-bones NSView subclass when I press Esc.

I checked and the Esc key is received on keyDown. Also, other action messages (such as moveLeft) are being called.

The view is part of a Window shown like this:

[self.window addChildWindow:wc.window ordered:NSWindowAbove];
[wc.window makeKeyAndOrderFront:self];

What am I doing wrong?

3

There are 3 best solutions below

0
On

My derived NSView had the same problem. It was resolved after implementing acceptsFirstResponder as follows:

- (BOOL)acceptsFirstResponder
{
    return YES;
}
0
On

In my case, I have an app with a couple of NSWindows. I had to call [self.window makeFirstResponder:self] in my NSView subclass to have the view respond to cancelOperation:.

2
On

Are you implementing it as cancelOperation or cancelOperation:? There's a big difference. The method signature should be:

- (void)cancelOperation:(id)sender

This works for me with a vanilla NSView.