0

I'm looking to send a backspace to my active UITextField once I shake my phone.

I'm catching the shake event fine but can't figure out how to send a backspace character to the first responder (active control).

Anyone able to help?

Peter Theill
  • 3,117
  • 2
  • 27
  • 29
  • What do you need help with? Determining the current first responder and whether it is a `UITextField` or how to call the `deleteBackward` method on the `UITextField`? – rmaddy Aug 17 '16 at 20:04
  • I'm basically trying to figure out how to call `deleteBackward` (and later also `insertText`) on whatever active responder I might have when I shake the device. – Peter Theill Aug 17 '16 at 20:19
  • http://stackoverflow.com/questions/1823317/get-the-current-first-responder-without-using-a-private-api – rmaddy Aug 17 '16 at 20:22
  • I entered up having to iterate subviews of the first view found being `firstResponder` .. then I would find the first subview being a `isFirstResponder` as well as a subview confirming to `UIKeyInput` using `confirmsToProtocol(@protocol(UIKeyInput)`. Finally I could typecast to `id` and perform my `insertText` and `deleteBackward` methods. Urgh :) – Peter Theill Aug 19 '16 at 06:33

1 Answers1

-2

You have to do it this way

if(_shakes){

NSString *strrr = _textField.text;

NSString *modStr = [strrr substringWithRange:NSMakeRange(0, [strrr length]-1)];

NSLog(@"Print %@",modStr);

_textField.text = modStr;

}