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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:10:05+00:00 2026-06-10T21:10:05+00:00

I have a UITextView subclass. UITextView class has some delegate protocols like – (void)textViewDidChange:(UITextView

  • 0

I have a UITextView subclass. UITextView class has some delegate protocols like

- (void)textViewDidChange:(UITextView *)textView;
- (void)textViewDidBeginEditing:(UITextView *)textView;

that I would like to use as they were from my custom class. In other words, if I use MyCustomTextViewClass from a class (lets call it classX), I have to do this and set the delegate:

MyCustomTextViewClass *box = [[MyCustomTextViewClass alloc] initWithFrame:
                                   CGRectMake(111.0f, 123.0f, 190.0f, 50.0f)];
// ... bla bla.. set other parameters
[box setDelegate:self];

but in order to set the delegate, I have to declare classX using

<MyCustomTextViewClassDelegate>

and to do that, I have to add UITextView’s delegate protocols to MyCustomTextViewClass.

How do I do that correctly?

simply do this on MyCustomTextViewClass?

@protocol MyCustomTextViewClassDelegate <NSObject>
@optional
- (void)textViewDidChange:(MyCustomTextViewClass *)textView;
- (void)textViewDidBeginEditing:(MyCustomTextViewClass *)textView;
@end

???
I don’t see how this could forward the delegate protocols from the UITextView…

thanks for any help.

  • 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-10T21:10:08+00:00Added an answer on June 10, 2026 at 9:10 pm

    EDIT: New answer. Please understand that a UITextView subclass does not need to declare its own delegate protocol. It works like this: not all rectangles are squares, but all squares are rectangles. Your MyCustomTextView will behave and respond to any messages that a UITextView responds to, and it will also send messages to its delegate just like a UITextView would. If you wanted to add additional delegate methods, that are not covered by UITextView, then you would create a brand new protocol.

    Anyway, think about why you need to subclass UITextView. Are you adding a subview to it, like a character counting label? It would be useful to subclass, in that case. If you’re just creating a UITextView and changing some of the exposed properties, a custom subclass may be overkill. The reason I ask is because this question makes it seem that you don’t quite understand object inheritance. Not trying to be a jerk or anything here, I want to help you.

    Anyway, to the code:

    //===================================
    //ClassX.h
    //===================================
    #import "MyCustomTextView.h"
    
    @interface ClassX : UIViewController <UITextViewDelegate>
    
    -(void)loadTextView;
    
    @property (nonatomic, strong) MyCustomTextView *customTextView;
    
    @end
    //===================================
    //ClassX.m
    //===================================
    #import "ClassX.h"
    
    @implementation ClassX
    @synthesize customTextView;
    
    -(void)loadTextView {
        if (!customTextView) {
            self.customTextView = [[MyCustomTextView alloc] initWithFrame:CGRectZero];
        customTextView.delegate = self;
        }
        customTextView.publicString = @"Public String Property!";    
    }
    
    #pragma mark UITextViewDelegate
    
    -(void)textViewDidChange:(UITextView *)textView {
        if (textView == customTextView) {
            //THIS IS CALLED A CAST :
            MyCustomTextView *castedVariable = (MyCustomTextView *)textView;
            //now the object castedVariable will be treated as a MyCustomTextView object
            //so you can access methods and variables declared by the class
            textView.publicString = @"Hello World!"; //XCode raises an error, UITextView doesn't have this property
            castedVariable.publicString = @"Hello World!"; //this works fine
            //handle textViewDidChange method
            //you are now interacting with self.customTextView
        } else {
            //is your ClassX also in charge of 
            //a different UITextView? Handle here
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITextview delegate - (BOOL)textView:(UITextView *)textView that is never getting called and
I have a UITextView subclass that has an NSIndexPath property that is inside a
I have a UITextView that has a lot of content. I have a button
I have a UITextView that has a fixed width and height. I pre-populate the
I have a UITextView that points to the File's Owner as its delegate, and
I have a UITextView that i use for typing some text (i have added
I have a UITextView that works well, till it's content is larger than it's
I have a UITextView and a WebView side by side and I would like
I have a UITextview in my Screen,I created textview in drag and drop on
I have a UITextView inside a UITableViewCell . It's working as expected except that

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.