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

  • Home
  • SEARCH
  • 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

I have a tun/tap device which is used to read incoming packets from one
I have attached 3 tap gesture recognizers to the same view - single, double
when i tap a button in web view which is connected to action-stop loading
There is a useful Ruby idiom that uses tap which allows you to create
I want to call the activity when user pull down the notification and tap
I have a functionality in my table view i.e. when you tap in on
I've setup a project with cloudmade. If if tap on a marker and want
I run some TAP Tests using TAP::Formatter::HTML. This CPAN module generates beautiful dynamic HTML
I have a need to tap and drag a UIView on the screen with
I have the following two 8-tap filters: h0 ['-0.010597', '0.032883', '0.030841', '-0.187035', '-0.027984', '0.630881',

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.