View Full Version : NSTextField:controlTextDidChange

Sep 18, 2008, 06:34 AM
I am using Cocoa with Obj C coding.
I have a NSSecureTextfield. I implemented the delegate controlTextDidChange to monitor whether the control is empty or nil and depending on that I am activating login button.

-(void) controlTextDidChange:(NSNotification *)aNotification
NSLog(@"Text changed: %@",[password stringValue]);
if([aNotification object] == password)
if( [[password stringValue] isEqualToString:@""] )
[loginButton setEnabled:NO];
[loginButton setEnabled:YES];


I am running the application from console so that I can see the statements.
I am always getting the message "NO" printed on the console.
And nothing is displayed for password.
How to handle this situation.

Sep 18, 2008, 12:35 PM
Nothing is displayed for the password?? Maybe your project/nib got corrupted. Obviously if nothing is showing in the UI then stringValue will always be empty.

Sep 18, 2008, 02:24 PM
That's a good question: are you seeing the dots as you type in the interface?

Also, is your secure text field inside some kind of accessory view, drawer, sheet, open/save box or modal window/panel? I did a search and found a person (http://lists.apple.com/archives/cocoa-dev/2007/Oct/msg01648.html) who had a problem similar to yours. What happens when you defocus the text field (tab out into another view)? You may have to temporarily add another focusable control to the nib to test this.

Try retrieving the value with

[[password currentEditor] string];

Sep 19, 2008, 01:03 AM
I am able to see the dots in the password textfield.

[password stringValue]

didn't work.

The following code suggested by HiRez worked.

[[password currentEditor] string];

But my question is why the other way of getting the text from a control
didn't work?
What's the basic difference between the two?

Sep 19, 2008, 05:26 AM
I just created a new project, added an NSSecureTextField, set its delegate and in controlTextDidChange: logged its stringValue. Worked as expected.

So I think something's somehow wrong with your project.