views:

229

answers:

1

Is it possible to detect at what text position the user tabs into a UITextField (just tabbing not editing, the text field is read-only)? E.g. by capturing the touches began event and then processing the tabbed position?

+1  A: 

Yes, set a delegate for UITextField and you can tell what the user is doing in the text field. See the UITextField class reference for details.

EDIT: OK, since it's a readonly text field, you should subclass UITextField and override the beginTrackingWithTouch:withEvent: and endTrackingWithTouch:withEvent: so you can see where the touch down and touch up occurred withing the UIControl (UITextField is a UIControl). Those methods are called with a UITouch object that tells you where the touch occurred within the UIControl (UITextField).

I don't know why you would want to do this. But anyway from there you'll have to figure out where in the text the touch occurred given the touch x,y offset in the control. That'll be another fun task to solve.

progrmr
I forgot to mention that it is a read-only text field, where the user is not editing anything
bertolami
Thanks. The reason is that I have a list of words, e.g. abc, xyz in the text field and I would like to react (similar to links) whenever a specific word, e.g. abc is tabbed. But probably I am better of by adding dynamically multiple text fields (or labels) and then determine which word was tabbed
bertolami
Buttons are just readonly text fields, use a UIButton for each one. P.S. on the iPhone, you get touches, not tabs.
progrmr