ShouldChangeCharactersInRange method is not called after startFirstResponder is called

Hi, I'm new to iOS,

I use multiple text fields in my project, so I want to use become FirstResponder for editing done for any text field. it works fine in xcode 3.2.5 , but it creates a problem in xcode 4.2.1

In xcode 4.2.1, after calling getFirstResponder, I could not edit the text field, it shows a virtual keyboard that I could press keys, but the keys pressed are not entered into the text field.

Please help me.

+4
source share
1 answer

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; } 
+13
source

All Articles