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!
views:
169answers:
2
+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
2009-12-17 04:20:18
+2
A:
You can setup a delegate and use
- (BOOL) textField: (UITextField *) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString *) string;
Ben Gottlieb
2009-12-17 04:22:28
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
2009-12-17 04:41:54