Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've got it! This is my delegate method implementation for the <code>shouldChangeCharactersInRange</code> method.</p> <hr> <pre><code>- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange) range replacementString:(NSString *) string { if ([string isEqualToString:@"⌫"]) { // NSLog(@"Backspace Pressed"); NSMutableString *text = [textField.text mutableCopy]; // NSLog(@"Length: %d Location: %d", range.length, range.location); if (range.length &gt; 0) { [text deleteCharactersInRange:range]; } if (range.length == 0 &amp;&amp; range.location != 0) { NSRange backward = NSMakeRange(range.location - 1, 1); // NSLog(@"Length: %d Location: %d", backward.length, backward.location); [text deleteCharactersInRange:backward]; } // NSLog(@"%@", text); textField.text = text; return NO; } else {return YES;} } </code></pre> <p>It works hand in hand with the <a href="http://dev.ragfield.com/2009/09/insert-text-at-current-cursor-location.html">UIPasteboard method</a> for getting text into a <code>UITextField</code>, which means that you have to link up your delete key to a method that pastes an arbitrary unicode character into your textfield (such as <code>⌫</code>), and when the delegate method is called, you recognise that the replacement string is that specific character.</p> <p>From there, you either delete the characters in <code>range</code> from your mutable string of the textField's text if there is an active selection, or you grab the previous character from the range if there is no selection, just a caret.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload