I have an NSView
subclass which implements acceptsFirstResponder
, resignFirstResponder
and becomeFirstResponder
. It also implements the following method:
-(void)keyDown:(NSEvent *) event {
[self interpretKeyEvents:[NSArray arrayWithObject:event]]; }
I handle the messages that interpertKeyEvent:
sends in an appController class (The appController is the NSWindow
delegate and therefore part of the responder chain).
This approach works fine for most message generated by interpertKeyEvent:
, eg insertNewline:
, moveUp:
and moveDown:
, but it does not work for insertText:
.
How do I get objects in the responder chain to handle insertText:
messages?
You have to implement the NSTextInput
protocol for your class, then insertText will be called. Have a look at nsterm.m in Aquamacs for an example of how to implement it.
According to the documentation the standard implementation by the NSResponder:
"The NSResponder implementation simply passes this message to the next responder, or beeps if there is no next responder."
Two possibilities come to mind: either your view isn't where you expect it to be in the responder chain, or your method signature doesn't match what is expected:
How are you implementing acceptsFirstResponder, resignFirstResponder, and becomeFirstResponder?
Is your application using NSWindowControllers or is it a Document Based application?
Further documentation regarding the event handling architecture:
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.