I need to react in a way specific to my iPhone app when the user is typing inside some UITextView field.
Three examples :
- I want to dismiss the keyboard if the user types in: ‘E’.
- I want to jump to a new input line if the user types in: ‘nN’.
- I want to ignore if the user types in: ‘A’ or ‘b’.
I am sure there must be a quite simple way to do what I want. But after browsing for a while on the net, I do not find a clear answer.
What is the way to go?
Thanks for any tip.
If you are using a
UITextField, give the text field a delegate (implementing theUITextFieldDelegateprotocol), and in the delegate, implementtextField:shouldChangeCharactersInRange:replacementString:. Examine the replacement string and take action based on whether it contains the characters you’re looking for.If you are using a
UITextView, give the text view a delegate (implementing theUITextViewDelegateprotocol), and in the delegate, implementtextView:shouldChangeTextInRange:replacementText:.