I know that there are already tons of posts on this subject, however none of them seem to work for me. I have a UITextField that I am using as my input method, and a custom keyboard that I am using via InputView. Its a digit-only keyboard, so it has keys 0-9, a decimal, a backspace key and a dismiss button. I am using
for each digit button and the decimal key to type in digits, etc. but I don't know how to get the backspace key to delete the previously entered character.
I was working on the same thing not long ago.
Here's what worked for me:
// set an NSString to whatever is in the textField
NSString *backspace = textField.text;
//set length of string to current length
lengthofstring = backspace.length;
//make length of string 1 less (takes off the last character)
backspace = [backspace substringToIndex:lengthofstring - 1];
//set textField to amended string
textField.text = backspace;
Of course, this will result in a crash if your textField is empty,
as the length of the string cannot be less than 0,
so you may want to rap it in a conditional statement such as:
if([textField.text length] >0)
{ }
to make sure it will only "backspace" when there's something there.
Hope that helps
Davo
__________________ Apps on App Store: Ohmulator (electric circuit calculator)
Hello, can i have a sample code to do a custom keyboard, please. I tried those samples given in this forum but none of them work.
I'd like to do like themaccity where you have another separate view for that keyboard.
Hi AdamsApple. What I did to get the custom view is actually quite simple. All you have to do is create an extra view in your ViewController's XIB, and give it an outlet called InputView. Then in your viewDidLoad method, add this line:
I was working on the same thing not long ago.
Here's what worked for me:
// set an NSString to whatever is in the textField
NSString *backspace = textField.text;
//set length of string to current length
lengthofstring = backspace.length;
//make length of string 1 less (takes off the last character)
backspace = [backspace substringToIndex:lengthofstring - 1];
//set textField to amended string
textField.text = backspace;
Of course, this will result in a crash if your textField is empty,
as the length of the string cannot be less than 0,
so you may want to rap it in a conditional statement such as:
if([textField.text length] >0)
{ }
to make sure it will only "backspace" when there's something there.
Hope that helps
Davo
am i missing something? i always get an error: "lengthofstring" undeclared