Move cursor to previous/next line in UITextView

  • In the iPhone/iPad simulator, you can use arrow-up and arrow-down keys on
    Mac to move the cursor to previous/next line in the UITextView. I'd like to
    create two buttons that implements the same functionalities.

    I didn't find any methods that let me do it easily. Any ideas on how to do
    this?

    Thanks,
    Peng
  • Hi,

    I'm guessing you mean just going down and up in the text view lines, not actual text lines? If that's the case, I don't believe that's doable. But if you want to go to the next or previous sentence, you can use the new line character set and some linguistic analysis. I recommend you check the WWDC '12 videos on the subject (Text and Linguistic Analysis).

    Best,
    Igor Ranieri

    On Jun 7, 2013, at 1:26 PM, Peng Gu <panygu...> wrote:

    > In the iPhone/iPad simulator, you can use arrow-up and arrow-down keys on
    > Mac to move the cursor to previous/next line in the UITextView. I'd like to
    > create two buttons that implements the same functionalities.
    >
    > I didn't find any methods that let me do it easily. Any ideas on how to do
    > this?
    >
    >
    > Thanks,
    > Peng
  • On Jun 7, 2013, at 4:26 AM, Peng Gu <panygu...> wrote:

    > In the iPhone/iPad simulator, you can use arrow-up and arrow-down keys on
    > Mac to move the cursor to previous/next line in the UITextView. I'd like to
    > create two buttons that implements the same functionalities.

    You should just be able to send it a fake key event whose key code is the appropriate arrow key’s.
    But I’m not nearly as familiar with events and responders in iOS as I am in Mac OS, so I couldn’t quickly find the method that receives key events.

    —Jens
  • I didn't find the key events methods either. Seems Apple doesn't provide it
    in iOS.

    Is there any way to calculate the number of characters for lines in
    UITextView ?

    On Sat, Jun 8, 2013 at 12:37 AM, Jens Alfke <jens...> wrote:

    >
    > On Jun 7, 2013, at 4:26 AM, Peng Gu <panygu...> wrote:
    >
    > In the iPhone/iPad simulator, you can use arrow-up and arrow-down keys on
    > Mac to move the cursor to previous/next line in the UITextView. I'd like to
    > create two buttons that implements the same functionalities.
    >
    >
    > You should just be able to send it a fake key event whose key code is the
    > appropriate arrow key’s.
    > But I’m not nearly as familiar with events and responders in iOS as I am
    > in Mac OS, so I couldn’t quickly find the method that receives key events.
    >
    > —Jens
    >
previous month june 2013 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today