NSTextView value changed

tarnfeld picture tarnfeld · Mar 5, 2011 · Viewed 12.4k times · Source

I'm pretty new to mac development (coming from a web and iOS background) and I can't work out how I could get a notification every time the value of an NSTextView changes. Any ideas?

Answer

lbrndnr picture lbrndnr · Mar 5, 2011

Ups I just saw that you want a callback from NSTextView and not NSTextField

Just add in the header of the object which should be the delegate the protocol

@interface delegateAppDelegate : NSObject <NSApplicationDelegate, NSTextViewDelegate> {
    NSWindow *window;
}

After that you add a method like

-(void)textDidChange:(NSNotification *)notification {
    NSLog(@"Ok");
}

Make sure you connected the delegate property of the NSTextView (not NSScrollView) with the object which should receive the delegate