PDA

View Full Version : Cursor placement in UITextField




davedelong
Aug 9, 2008, 08:38 PM
Hi everyone,

I've got a UITextField on my interface that, for various reasons, I'm not using the keyboard to input text into. I'm using a bunch of buttons beneath it (I suppose like the calculator app).

My buttons all work fine in putting text into the UITextField, but once the text extends beyond the length of the screen, I see this:
"all the stuff I've writt..."

What I really want to see is this:
"... the stuff I've written"

How can I scroll my UITextField programmatically?

Thanks,

Dave



davedelong
Aug 11, 2008, 11:06 PM
*bump*

imho
Aug 13, 2008, 12:34 AM
Use scrollRangeToVisible. You need to pass in a NSRange parameter.

davedelong
Aug 13, 2008, 09:08 AM
Use scrollRangeToVisible. You need to pass in a NSRange parameter.

Hi imho,

I tried to do as you suggested using:
NSString * newText = @"Whatever it is I'm using for the really long text value";
[myUITextField setText: newText];
[myUITextField scrollRangeToVisible:NSMakeRange([newText length], 1)];

When I run that code, I first get a compiler warning the UITextField may not respond to "scrollRangeToVisible:", and once that code is executed, my app crashes because:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UITextField scrollRangeToVisible:]: unrecognized selector sent to instance 0x45a040'

dave

abogdziewicz
Apr 27, 2009, 05:16 AM
Method scrollRangeToVisible: is for class UITextView in iPhone SDK. Has anyone solved this issue? I know it is possible to do because address bar in Safari does that.