Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

satyam90

macrumors regular
Original poster
Jul 30, 2007
242
0
Bangalore, India
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.
Code:
-(void) controlTextDidChange:(NSNotification *)aNotification
{
	NSLog(@"Text changed: %@",[password stringValue]);
	if([aNotification object] == password)
	{
		if( [[password stringValue] isEqualToString:@""] )
		{
                        NSLog(@"NO");
			[loginButton setEnabled:NO];
		}
		else
		{
                        NSLog(@"YES");
			[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.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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.
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
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 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

Code:
[[password currentEditor] string];
 

satyam90

macrumors regular
Original poster
Jul 30, 2007
242
0
Bangalore, India
I am able to see the dots in the password textfield.
But
Code:
[password stringValue]
didn't work.

The following code suggested by HiRez worked.
Code:
[[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?
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.