15

Possible Duplicate:
Detect backspace in UITextField

I want to detect when backspace is pressed on the keyboard, even when a UITextField is empty.

I tried to use ShouldChangeCharachtersInRange, but it does not get called when the backspace is called and the text is empty.

How can I solve this?

Community
  • 1
  • 1
Blondy314
  • 751
  • 9
  • 24
  • possible duplicate of this http://stackoverflow.com/questions/1977934/detect-backspace-in-uitextfield and this http://stackoverflow.com/questions/6818342/how-to-detect-uikeyboard-backspace-button-touch-on-uitextfield.These links provide you the solution you want – Pratyusha Terli Nov 30 '12 at 11:33
  • I'm trying to understand the logic here. shouldChangeCharactersInRange won't be called when pressing back if the field is empty because there aren't any characters to change. – Mick MacCallum Nov 30 '12 at 11:41
  • I have a crossword in which every square is a TextField. What I want is that when the user presses the backspace key (when the TextField is empty), the focus will go the TextField that comes before it. This is why I need to detect when its called – Blondy314 Nov 30 '12 at 11:44
  • @user721577 make every square a custom subclass of `UILabel` that conforms to the `UIKeyInput` protocol. Then, return `true` for `canBecomeFirstResponder`. `deleteBackward` always gets called, even when `hasText` returns `false`. http://stackoverflow.com/a/6637821/242933 – ma11hew28 Jul 19 '14 at 13:46

1 Answers1

-5

Have you defined the delegate of UITextview in .h file or just assign delegate to self in .m file. Like textfield.delegate = self.

ask4asif
  • 676
  • 4
  • 10