views:

169

answers:

2

How can I get a textDidChange method for a UITextField? I need to call a method every time a change is made to a text field. Is this possible? Thanks!

+2  A: 

You can use the UITextFieldTextDidChangeNotification to call a method whenever the text field changes. Add this to your init:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange:) name:UITextFieldTextDidChangeNotification object:nil];
Chris Long
+2  A: 

You can setup a delegate and use

- (BOOL) textField: (UITextField *) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString *) string;
Ben Gottlieb
Thanks! That worked beautifully. I had to do the following to get the full string: NSMutableString *textFieldString = [NSMutableString stringWithString:textField.text]; [textFieldString appendString:string];
Jonah