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?
My derived NSView
had the same problem. It was resolved after implementing acceptsFirstResponder
as follows:
- (BOOL)acceptsFirstResponder
{
return YES;
}
In my case, I have an app with a couple of NSWindow
s. I had to call [self.window makeFirstResponder:self]
in my NSView
subclass to have the view respond to cancelOperation:
.
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.