First add delegates to the interface:
@interface yourViewController : UIViewController<UITextFieldDelegate>
If you are using xib, right-click on UITextField and associate the delegate with the file server else add this code to the viewDidLoad method.
yourTextField.delegate = self;
Add a UITextField delegate and it will be called
- (BOOL)textFieldShouldReturn:(UITextField *)textField //resign first responder for textfield { [textField resignFirstResponder]; return YES; } - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { return YES; }
source share