Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-28-2010, 11:35 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 14
themaccity is on a distinguished road
Default Custom Keyboard Backspace

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

textField.text = [textField.text stringByAppendingString:@"Character"];

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.
__________________
themaccity

Buy my app, QuickTipper today!
http://bit.ly/quicktipperdownload

Follow me on Twitter!
http://twitter.com/themaccity

Subscribe to me on Youtube!
http://youtube.com/themaccity
themaccity is offline   Reply With Quote
Old 11-28-2010, 10:40 PM   #2 (permalink)
Go Tiges!
 
Davo's Avatar
 
Join Date: Oct 2010
Location: Australia
Posts: 15
Davo is on a distinguished road
Default

Hi themaccity,

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)
Davo is offline   Reply With Quote
Old 11-28-2010, 10:48 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 97
AdamsApple is on a distinguished road
Default

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.
AdamsApple is offline   Reply With Quote
Old 11-30-2010, 05:13 PM   #4 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 14
themaccity is on a distinguished road
Default

Quote:
Originally Posted by AdamsApple View Post
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:
Code:
[yourTextField setInputView:InputView]
Hope it works out
__________________
themaccity

Buy my app, QuickTipper today!
http://bit.ly/quicktipperdownload

Follow me on Twitter!
http://twitter.com/themaccity

Subscribe to me on Youtube!
http://youtube.com/themaccity
themaccity is offline   Reply With Quote
Old 11-30-2010, 06:25 PM   #5 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 14
themaccity is on a distinguished road
Default

Quote:
Originally Posted by Davo View Post
Hi themaccity,

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
__________________
themaccity

Buy my app, QuickTipper today!
http://bit.ly/quicktipperdownload

Follow me on Twitter!
http://twitter.com/themaccity

Subscribe to me on Youtube!
http://youtube.com/themaccity
themaccity is offline   Reply With Quote
Old 11-30-2010, 07:41 PM   #6 (permalink)
Go Tiges!
 
Davo's Avatar
 
Join Date: Oct 2010
Location: Australia
Posts: 15
Davo is on a distinguished road
Default

oops sorry,
my bad,

The problem is here:

lengthofstring = backspace.length;

"lengthofstring" should be declared as an integer.

make it:
int lengthofstring = backspace.length;

or declare it earlier, as I had done, that's why I accidentally left it out

Hope that helps

Davo
__________________
Apps on App Store: Ohmulator (electric circuit calculator)

Last edited by Davo; 11-30-2010 at 07:46 PM.
Davo is offline   Reply With Quote
Reply

Bookmarks

Tags
textfield, uitextfield

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 373
7 members and 366 guests
daudrizek, HemiMG, Kirkout, MarkC, Sami Gh, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:48 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0