Investmoney
Investmoney

Reputation: 17

Delete text from backspace

I can't find tutorial that does this. I have...

UIbutton 
UItext.text

I want to make my own KEYBOARD user interface without iphone keyboard. I want to press the UIbutton(keyboard "delete" key or backspace) from text. Not ease the whole thing like UIText.text = @"". I've seen programmers give the wrong code. I'm looking for something like Visual Basic Sendkeys {Delete}. How do I do this on iphone button? http://gigaom.com/apple/iphone-os-where-the-delete-key-belongs/

For example:

Text1
Text<=
Tex<=

Upvotes: 1

Views: 697

Answers (2)

XMLSDK
XMLSDK

Reputation: 259

if ([textField.text length] != 0) {
    textField.text = [textField.text substringToIndex:[textField.text length]-1];
}

Upvotes: 1

Alex Coplan
Alex Coplan

Reputation: 13371

Implement the following method to delete the last character.

- (NSString *)deleteLastChar:(NSString *)str {
    if (![str length]) return @""; 
    return [str substringToIndex:[str length]-1];
}

You can then use that on your text field's text property e.g:

textField.text = [self deleteLastChar:textField.text];

Upvotes: 3

Related Questions