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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:09:46+00:00 2026-05-28T07:09:46+00:00

I have a UITextview delegate – (BOOL)textView:(UITextView *)textView that is never getting called and

  • 0

I have a UITextview delegate - (BOOL)textView:(UITextView *)textView that is never getting called and I have been struggling with this for a couple of days to no avail. Here is what I have

I have declared the <UITextViewDelegate> in my header file and in ViewDidLoad I am setting the delegate, I have tried self.myTextView.delegate = self;
and myTextView.delegate = self; along with wiring up the delegate in the NIB file instead of declaring it programmatically.

I have a few custom buttons that insert the text into my UITextView by 2 different methods depending on the button, the first method here is…

-(IBAction)string1:(id)sender {

NSRange range = myTextView.selectedRange;  
NSString * firstHalfString = [myTextView.text substringToIndex:range.location];  
NSString * secondHalfString = [myTextView.text substringFromIndex: range.location];  
myTextView.scrollEnabled = NO;  

NSString * insertingString = [NSString stringWithFormat:@"insert my text string"];

myTextView.text = [NSString stringWithFormat: @"%@%@%@",  
                 firstHalfString,  
                 insertingString,  
                 secondHalfString];  
range.location += [insertingString length];  
myTextView.selectedRange = range;  
myTextView.scrollEnabled = YES;}

and the second method is …

-(IBAction)string2:(id)sender {

myTextView.text = [myTextView.text stringByAppendingString:@"my other string value"];}

With NSLog turned on, I can see that

- (void)textViewDidChange:(UITextView *)textView{
 NSLog(@"something changed");}

does get called but this delegate never gets called

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
NSUInteger newLength = (textView.text.length - range.length) + text.length;
if(newLength <= MAX_LENGTH)
{
    return YES;
} else {
    NSUInteger emptySpace = MAX_LENGTH - (textView.text.length - range.length);
    textView.text = [[[textView.text substringToIndex:range.location] 
                      stringByAppendingString:[text substringToIndex:emptySpace]]
                     stringByAppendingString:[textView.text substringFromIndex:(range.location + range.length)]];
    return NO;
}
NSLog(@"something else changed");}

At the top of my .M file I have defined #define MAX_LENGTH 100

Any help would be very much appreciated, my overall goal is to limit the number of charters in the UITextView.

  • 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-28T07:09:47+00:00Added an answer on May 28, 2026 at 7:09 am

    UITextView only sends textView:shouldChangeTextInRange:replacementText: to its delegate in response to user events. It does not send that message when your program sets the myTextView.text property.

    I’m surprised that the UITextView is sending textViewDidChange: to the delegate, since the documentation says “This method is not called in response to programmatically initiated changes.”

    So, you could clip the text in textViewDidChange: instead (and rely on its behavior being different from the documentation), or modify and string1: and string2: to clip the text.

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

Sidebar

Related Questions

I have a ViewController that has a couple of IBOutlet properties defined for UITextView.
I have a UITextView that points to the File's Owner as its delegate, and
I have a UITextView that has a lot of content. I have a button
I have some text in a UITextView, that I would like to have show
I have a UITextView on a View that becomes the first responder. When I
I have a UITextView inside a UITableViewCell . It's working as expected except that
I have a UITextView that is supposed to have one line of text. The
I have a UITextView within a UITableView cell. I have been unable to get
I have created a UITextView programatically and want to enable scrolling for that UITextView.
I have a UIViewController that implements UITextViewDelegate and is connected as the delegate to

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.