03-21-2010, 12:05 PM
#1 (permalink )
Obj-C Learner
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
UIKeyboard detection
I need to find a way to detect key presses when the Keyboard pops up, and possibly telling me which letter was pressed?
Will I have to make my own keyboard here or what?
__________________
Will code for food
03-21-2010, 12:12 PM
#2 (permalink )
Registered Member
Join Date: Dec 2008
Location: UK
Posts: 1,886
It depends which control you're using. Some things like the UITextField have a delegate method for handling key presses.
03-21-2010, 12:17 PM
#3 (permalink )
Obj-C Learner
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
Quote:
Originally Posted by
harrytheshark
It depends which control you're using. Some things like the UITextField have a delegate method for handling key presses.
I'm using UITextView.
__________________
Will code for food
03-21-2010, 12:21 PM
#4 (permalink )
Registered Member
Join Date: Dec 2008
Location: UK
Posts: 1,886
In that case, you can use:
Code:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
Where "text" is the text or key that was just entered.
03-21-2010, 12:23 PM
#5 (permalink )
Obj-C Learner
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
Ah cool, I came across that but it didn't seem to be what I was looking for.
__________________
Will code for food
03-21-2010, 12:24 PM
#6 (permalink )
Obj-C Learner
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
Also, how would I see if the delete key was pressed?
__________________
Will code for food
03-21-2010, 12:35 PM
#7 (permalink )
Registered Member
Join Date: Dec 2008
Location: UK
Posts: 1,886
The string entered is nothing. You can only capture the backspace when there is text in the view, otherwise the delegate method isn't called.
03-28-2010, 05:00 PM
#8 (permalink )
Obj-C Learner
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
I tried it (just got around to it) and the method isn't being called. I've put UITextViewDelegate inbetween the <> in the .h and in the method ive put return YES; at the bottom, what else?
__________________
Will code for food
Last edited by ZunePod; 03-28-2010 at 05:02 PM .
03-28-2010, 06:09 PM
#9 (permalink )
Registered Member
Join Date: Dec 2008
Location: UK
Posts: 1,886
Works fine for me:
Code:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
NSLog(@"%@",text);
return YES;
}
03-28-2010, 06:45 PM
#10 (permalink )
Registered Member
Join Date: Sep 2009
Posts: 126
Quote:
Originally Posted by
ZunePod
I tried it (just got around to it) and the method isn't being called. I've put UITextViewDelegate inbetween the <> in the .h and in the method ive put return YES; at the bottom, what else?
Did you set the delegate to self?
Code:
myTextView.delegate = self;
03-28-2010, 07:23 PM
#11 (permalink )
Obj-C Learner
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
Thanks for that guys. It's always the simple things.
__________________
Will code for food
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 257
20 members and 237 guests
ADY , Alsahir , beleg_1998 , Dani77 , e2applets , iph_s , JamesCahall , JasonR , mer10 , Monstertaco , piesia , prchn4christ , Promo Dispenser , Robiwan , Rudy , smithdale87 , timle8n1 , Touchmint , twerner
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,756
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris