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 7888915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:57:37+00:00 2026-06-03T05:57:37+00:00

URL I am adding text inside the uitextview using uipickerview. Currently i am adding

  • 0

URL I am adding text inside the uitextview using uipickerview.

Currently i am adding the text as below ( did select row method )

self.myTextView.text = [NSString stringWithFormat:@"%@ %@", self.myTextView.text,
            [myTierThreeData objectAtIndex:row]];

This works fine but i wanted to insert text where the cursor is so i did the below

-(void) pickerViewShown:(id)sender{
  myCursorPosition = [self.myTextView selectedRange];
}

When ever the pickerview is shown, taken the cursor position in the member variable.

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

NSString *contentsToAdd = [myData objectAtIndex:row];
NSMutableString *tfContent = [[NSMutableString alloc] initWithString:[self.myTextView text]];
// add content where the cursor was
NSString *contentsToAddPadded = [NSString stringWithFormat:@"%@ ", contentsToAdd];

[tfContent insertString:contentsToAddPadded atIndex:myCursorPosition.location];
[self.myTextView setText:tfContent];
[tfContent release];

myCursorPosition = [self.myTextView selectedRange];
}

the above code works for the first time but when try to add next text , it appends the text at the end.

please let me know what is wrong with the above code

  • 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-06-03T05:57:38+00:00Added an answer on June 3, 2026 at 5:57 am

    Probably setting the text for the text field resets the cursor position to the end, so the only chance you have is to calculate the new cursor position yourself:

    • When starting the picker view, remember the original cursor position
      (like you do now) in myCursorPosition.
    • Every time you append text,
      add the text length to myCursorPosition, and use that value for
      inserting the next text.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below detects URL's in a body of text and wraps them in
How can I include a url in an outgoing text message using twilio API?
Thanks everyone adding the name to the select tag did the trick. but now
I am adding a row using the clone() function and then am having to
By adding a custom handler to the SiteMapResolve event, I can update sitemap url's
<script type=text/javascript> $(function() { $('#wp-calendar a').click(function(event) { event.preventDefault(); var url = $(this).attr('href') + '
- (void)loadLocations { NSString *url = @<URL to a text file>; NSStringEncoding enc =
I have a web form with a text input box for a url. When
I'm adding a script reference to a page header using a HtmlGenericControl. The problem
I'm getting strange additional symbols (=) in text property when adding text there via

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.