In the project that I'm building, I'd like to have a method called when I paste some text into a specific text field. I can't seem to get this to work, but here's what I've tried
I implimented a custom class (based on NSObject) to be a delegate for my textfield, then gave it the method: textDidChange:
class textFieldDelegate(NSObject):
def textDidChange_(self, notification):
NSLog("textdidchange")
I then instantiated an object of this class in interface builder, and set it to be the delegate of the NSTextField. This however, doesn't seem to do anything. However, when I build the example code from http://www.programmish.com/?p=30, everything seems to work perfectly fine. How do I impliment this delegate code so that it actually works?
The reason this isn't working for you is that textDidChange_
isn't a delegate method. It's a method on the NSTextField
that posts the notification of the change. If you have peek at the docs for textDidChange
, you'll see that it mentions the actual name of the delegate method:
This method causes the receiver’s delegate to receive a controlTextDidChange: message. See the NSControl class specification for more information on the text delegate method.
The delegate method is actually called controlTextDidChange_
and is declared on the NSTextField
superclass, NSControl
.
Change your delegate method to:
def controlTextDidChange_(self, notification):
NSLog("textdidchange")
and it should work for you.