How to know which key is pressed on UIKeyboard in ios? [closed]

允我心安 提交于 2019-12-20 06:21:30

问题


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.



来源:https://stackoverflow.com/questions/12417976/how-to-know-which-key-is-pressed-on-uikeyboard-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!