Cursor placement in UITextField

Discussion in 'iOS Programming' started by davedelong, Aug 9, 2008.

  1. davedelong macrumors member

    davedelong

    Joined:
    Sep 9, 2007
    Location:
    Right here.
    #1
    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
     
  2. davedelong thread starter macrumors member

    davedelong

    Joined:
    Sep 9, 2007
    Location:
    Right here.
  3. imho macrumors newbie

    Joined:
    Jul 31, 2008
    #3
    Use scrollRangeToVisible. You need to pass in a NSRange parameter.
     
  4. davedelong thread starter macrumors member

    davedelong

    Joined:
    Sep 9, 2007
    Location:
    Right here.
    #4
    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
     
  5. abogdziewicz macrumors newbie

    Joined:
    Apr 24, 2009
    #5
    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.
     

Share This Page