Search code examples
macososx-mountain-lion

OS X - delegate method equivalent to textShouldBeginEditing


I am new to OSX programming.

I would like to do a very simple app with the purpose of learning. The app is a NSTextView and a label.

The idea is for the label to show the character count of the textview.

Looking at NSTextView delegate methods, I don't manage to see which method is called every time a character is typed. Something like textField's textShouldBeginEditing.

How do I do that?


Solution

  • -(void)awakeFromNib{
        [[NSNotificationCenter defaultCenter]addObserver :self
                                            selector:@selector(myTextChanged:)
                                                name:NSTextDidChangeNotification
                                              object:nil];
    }
    
    
    -(void)myTextChanged:(NSNotification *)aNotification{
        [textfieldLabel setString:[NSString stringWithFormat:@"ld",[textField.string length]];
    }