shouldChangeCharactersInRange method not called after calling becomeFirstResponder

thavasidurai picture thavasidurai · Aug 27, 2012 · Viewed 9.7k times · Source

Hi i am new to the iOS,

i am using several text fields in my project, so i want use becomeFirstResponder for editing done for any one of text field. it is working fine in xcode 3.2.5 but it makes problem in xcode 4.2.1

In xcode 4.2.1 after calling the becomeFirstResponder i could not edit the text field, it is showing the virtual key board i could tap the keys but tapped keys are not entered in text field.

Please help me out.

Answer

Paresh Navadiya picture Paresh Navadiya · Aug 27, 2012

Firstly add this delegates in interface:

 @interface yourViewController : UIViewController<UITextFieldDelegate>

If using from xib then right click on UITextField and bind delegate with fileowner else add this code in viewDidLoad's method.

  yourTextField.delegate = self;

Add UITextField's 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;
 }