views:

135

answers:

1

I have a UITextField in my iPhone app. I know how to make the text field select all of its text, but how can change the selection? Say I wanted to select the last 5 characters, or a specific range of characters, is that possible? if not, can I move the lines marking the beginning and end of the selection, as if the user is dragging them?

A: 

With UITextField, you cannot. But if you see the headers, you have _selectedRange and others that might be used if you add some categories to it ;)

nacho4d
I don't really understand what you mean.since you said it's not possible with text fields, I tried using a textview, which does have a selectedRange field, though I can't seem to get either the getter or setter to work.for example:txtDescription.selectedRange = NSMakeRange(0, 5);I was hoping this would select the first 5 characters in txtDescription, which is a UITextView*, but it doesn't.any ideas?
Sunian314
nevermind, I solved my problem with a different approach not involving text selection. thanks for your advice anyway.
Sunian314
BTW, selectedRange works when the textView is first responder (when is editing for example.) Ask for selectedRange and you will get the cursor position or selection range if there is a selection. Set it and the cursor will change ;)
nacho4d