NSTextField:controlTextDidChange

Discussion in 'Mac Programming' started by satyam90, Sep 18, 2008.

  1. macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #1
    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.
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    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.
     
  3. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #3
    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];
     
  4. thread starter macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #4
    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?
     
  5. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #5
    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.
     

Share This Page