Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

davedelong

macrumors member
Original poster
Sep 9, 2007
50
0
Right here.
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
 
Use scrollRangeToVisible. You need to pass in a NSRange parameter.

Hi imho,

I tried to do as you suggested using:
Code:
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
 
Method scrollRangeToVisible:

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.