Search code examples
iphoneobjective-cuitextviewuikeyboarduitextviewdelegate

How to know the pressed key in the keyboard in iPhone


I am new to iPhone. I'd like to know the key pressed in the keyboard, and instead of the letter of the key I'd like to insert another letter in UITextView.

So for this are there any methods which will be called when a key is pressed in the key board and the methods in which we can change the letter of that key, which will be written to the UITextView ?

Thanks in advance.


Solution

  • The UITextViewDelegate Protocol provides a way of intercepting characters as the are typed using:

    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
    

    at this point you can return NO and do your own text replacement.