3

dose anyone know how to detect a delete press from a numberpad in ios?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
tinhead
  • 385
  • 2
  • 10
  • 29

2 Answers2

4

If you're using a UITextField, your delegate's textField:shouldChangeCharactersInRange:replacementString: will be called with a range of length 1 and an empty replacement string. If nothing is deleted, however, you will get no notification.

If you're using a UITextView, your delegate's textView:shouldChangeTextInRange:replacementText: will be called with a range of length 1 and an empty replacement string. If nothing is deleted, however, you will get no notification.

If you're using your own class that implements UIKeyInput, deleteBackward is supposed to be called. I don't know whether a class implementing UITextInput (which itself includes UIKeyInput) might ever have replaceRange:withText: or setMarkedText:selectedRange: called instead with a range of length 1 and an empty replacement string, or what might happen in those cases if there is nothing to delete.

Anomie
  • 92,546
  • 13
  • 126
  • 145
0

If you are implementing something like a passcode, I think a hidden textfield would be preferable, and more controls.

rexsheng
  • 161
  • 2
  • 3