Getting the Value of a UITextField as keystrokes are entered?

Posted by Nocturne on Stack Overflow See other posts from Stack Overflow or by Nocturne
Published on 2008-12-23T05:20:39Z Indexed on 2010/04/29 13:47 UTC
Read the original article Hit count: 374

Filed under:
|
|

Let's say I have the following code:

IBOutlet UITextField* nameTextField;
IBOutlet UILabel* greetingLabel;

I'd like the greetingLabel to read "Hello [nameTextField]" as soon as the user presses any key.

What I need basically is the iPhone equivalent of the Cocoa delegate method -controlTextDidChange:

The -textField:shouldChangeCharactersInRange: delegate method is called each time a keystroke occurs:

- (BOOL)              textField:(UITextField *)textField
  shouldChangeCharactersInRange:(NSRange)range     
              replacementString:(NSString *)string

The string argument returns the character that is pressed. The actual textField's value (nameTextField.text) remains blank however.

What am I missing here? (I'd like nameTextField to reflect the exact string that the user has entered so far)

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk