tags:

views:

171

answers:

2

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?

A: 

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:

  • (void)insertText:(id)aString

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:

http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/10000060i-CH3-SW2

Evan
A: 

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.

Mattias Wadman