Kgrover
Kgrover

Reputation: 2116

UITextField onText Changed

I need to survey a textField's value every time it's changed. To handle this, I simply added that action to the .h file and implemented that method in the .m file. (That is, I "ctrl+click"ed the "Value Changed" event from the Storyboard and dragged it onto my .h file). Even if I just try to NSLog from the method, it's not logging anything, whether the value of my textbox is changed or not.

My header file includes the following:

(IBAction)changed:(UITextField *)sender;

and my .m file has the following:

 (IBAction)changed:(UITextField *)sender {

NSLog(@"%@", @"Changed");

}

Upvotes: 0

Views: 1561

Answers (3)

Hejazi
Hejazi

Reputation: 17015

Just try "Editing Changed" instead of "Value Changed".

Upvotes: 3

Kjuly
Kjuly

Reputation: 35131

You can use the notification name UITextFieldTextDidChangeNotification to listen the text did changed event:

[[NSNotificationCenter defaultCenter] addObserver:self
                                       selector:@selector(_yourTextFieldDidChangedMethod:)
                                           name:UITextFieldTextDidChangeNotification
                                         object:self.yourTextField];

and the selector:

- (void)_yourTextFieldDidChangedMethod:(NSNotification *)notification {
   // do your work here
}

Upvotes: 1

jscs
jscs

Reputation: 64002

Make one of your controllers the text field's delegate and implement textField:shouldChangeCharactersInRange:replacementString:

Upvotes: 3

Related Questions