cocoafirst-responderresponder-chain

tryToPerform:with: not being called when keyDown: is being called


I have a NSViewController which I manually put into the responder-chain by calling

self.nextResponder = self.view.nextResponder;
self.view.nextResponder = self;

When the user presses keys inside the view, I am able to successfully receive keyDown: messages. However, for some reason I'm not receiving tryToPerform:with: and validateMenuItem: messages when the user access the MainMenu bar. What am I missing here?


Solution

  • Turns out that actually a respondsToSelector: message is being sent first before the validateMenuItem: is being called. And if the NSViewController doesn't actually respond to the message, the validateMenuItem never quite gets called. That said, in the whole process I never saw tryToPerform:with: getting called at all. Not sure why, going to look into Cocoa's Event Programming guide and report back.