NSTextView subclass & NSResponder issue with cancelOperation.

I have an NSTextView subclass, and I'm overriding the NSResponder declared method cancelOperation(_:) to handle the escape key.


Sometimes I want to consume the event, and othertimes I'd like to pass the method onto the next responder in the chain (and let it bubble up to the content view controller of the window).


My understanding was I do this by simply calling super.cancelOperation(sender), but this causes an "unrecognized selector sent to instance" exception. NSTextView doesn't respond to cancelOperation.


What's the right way to let the event continue up the responder chain?

Did you try calling

next?.cancelOperation(sender)

Yes, the method then gets sent to the textView's clipView, which also doesn't implement the method, triggering the unrecognized selector sent to instance exception.

Accepted Answer

You should do nextResponder?.tryToPerform(:#selector(cancelOperation) with:sender).

NSTextView subclass & NSResponder issue with cancelOperation.
 
 
Q