Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3405638
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:31:48+00:00 2026-05-18T05:31:48+00:00

When I tap on a certain position in a UITextView, I want to retrieve

  • 0

When I tap on a certain position in a UITextView, I want to retrieve the substring of the NSString which is shown at the line.

I have e.g. a UITextView which displays a string, using 16 lines. When I tap on position (200, 150), I want the substring which is shown by UITextView on that tap.

Any suggestions on how to achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:31:49+00:00Added an answer on May 18, 2026 at 5:31 am

    If I understand your question correctly this is a possible solution. In your viewcontroller add an IBOutlet to a UITextView and make sure your viewcontroller implements the UITextViewDelegate. When connecting the UITextView to the FileOwner in InterfaceBuilder make sure you also point the delegate of the UITextView to the FileOwner.

    @interface StackOverFlowViewController : UIViewController<UITextViewDelegate> {
    
        IBOutlet UITextView *textView;
    }
    @end
    

    Then in your UIViewController implementation file add this UITextViewDelegate Method.

    - (void)textViewDidChangeSelection:(UITextView *)aTextView {
    
      NSRange rangeOfSelection = textView.selectedRange;
      NSString *selectedText = [textView.text substringWithRange:rangeOfSelection];
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Selection Changed" message:selectedText delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
      [alert show];
      [alert release];
    }
    

    Then each time you make a selection in the UITextView this method will get called. Use the selectedRange property of UITextView to get the NSRange the User made. From there you can just get the text from the UITextView and generate the correct substring.

    I just added a UIAlertView in the textViewDidChangeSelection method to display the substring

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i have a sentence (TextView) and I want to tap a certain word
I'm using a tap gesture recognizer to position a little subview with a label
I have a button that when i tap on it i want to invoke
I want to tap a control on the screen and have the ListView scroll
I have a tap gesture on my view that I only want to be
I have a tun/tap device which is used to read incoming packets from one
I have a 64-tap FIR filter whose output format I am having trouble understanding.
I want to test for a tap event within a Core Text CTLineRef variable.
I have a web service I'm offering to users to tap into my applications
I have a table view, and if a certain row is tapped, the detail

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.