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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 06-02-2009, 09:11 PM   #14 (permalink)
slahteine
Programming Wizard
 
slahteine's Avatar
 
Join Date: Oct 2008
Location: Northampton, MA USA
Age: 45
Posts: 193
Send a message via AIM to slahteine Send a message via Yahoo to slahteine Send a message via Skype™ to slahteine
Default

Quote:
Originally Posted by nacho4d View Post
In case of UITextView I think can calculate the actual position by a function of the tapped position, and current font sizes. But I don't know how accurate this method can be. I case of UITextField I am not sure whether I can do it.
Normally you don't need to know the cursor position ahead of the keypress. The cursor position becomes available to you when the key is pressed. So assuming you can generate a real keypress event instead of using the method from the example, do the usual thing...

Just implement a UITextFieldDelegate and in particular the method:
Code:
textField:shouldChangeCharactersInRange:replacementString:
The range corresponds to the current cursor position and the string corresponds to the pressed key. If you want to allow the keypress at the given cursor position, return YES. If you don't like it, just return NO. If you want to substitute something in place of the pressed key, use something like
Code:
[textField setText:[ textField.text stringByReplacingCharactersInRange:range
    withString:@"Q" ] ];
and return NO.

Of course, since there's no publicly documented way to generate a "keypress" event then I guess you may still be stuck!

Oh wait, never mind... In just poking around, I see there's a handy method/property if you use a UITextView instead of a UITextField:
Code:
[myTextView selectedRange]
That may be helpful, if you can dress up the text view to look more like a text field, and add the clear button to it, and so forth.... I still don't understand why this method isn't available in a text field. It's obviously very handy.
__________________
|
| I wrote ChordCalc ... A cool fretboard calculator.
|


Last edited by slahteine; 06-02-2009 at 09:41 PM.
slahteine is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,868
Threads: 89,225
Posts: 380,691
Top Poster: BrianSlick (7,129)
Welcome to our newest member, stokesreece
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:16 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.