How to know which key is pressed on UIKeyboard in

2020-05-01 08:03发布

问题:

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 7 years ago.

I am implementing a iPad application. In my application I need to know which key is pressed in the keyborad. Can you guys please help me is there any way to find it?

Thank you, Sekhar.

回答1:

This is a vague question, but if you simply want to know what key has been tapped you need to implement a delegate for input control that called the keyboard. For example if you are using a UITextView, then implement the UITextViewDelegate, wire up the control's delegate property to you class, and then implement the textView:shouldChangeTextInRange:replacementText:. When UITextView recognizes a change then it will call this method. You can then watch for the characters in the "replacementText" argument.

With UITextField use the UITextFieldDelegate and implement the textField:shouldChangeCharactersInRange:replacementString: method.

You can do other things with UITextField like change the Return button to a Done button in Interface Builder. The implement the textFieldShouldReturn: method. If it's called then run the resignFirstResponder on the object passed to the method.

Hope this helps.