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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:40:58+00:00 2026-05-14T23:40:58+00:00

I want to subclass UITextView, and send a new message to the delegate. So,

  • 0

I want to subclass UITextView, and send a new message to the delegate. So, I want to extend the delegate protocol. What’s the correct way to do this?

I started out with this:

interface:

#import <Foundation/Foundation.h>

@class MySubClass;

@protocol MySubClassDelegate <UITextViewDelegate>
- (void) MySubClassMessage: (MySubClass *) subclass;
@end


@interface MySubClass : UITextView {
}

@end

implementation:

#import "MySubClass.h"


@implementation MySubClass

- (void) SomeMethod; { 
    if ([self.delegate respondsToSelector: @selector (MySubClassMessage:)]) { 
        [self.delegate MySubClassMessage: self];
    }
}

@end

however with that I get the warning: '-MySubClassMessage:' not found in protocol(s).

I had one way working where I created my own ivar to store the delegate, then also stored the delegate using [super setDelegate] but that seemed wrong. perhaps it’s not.

I know I can just pass id’s around and get by, but My goal is to make sure that the compiler checks that any delegate supplied to MySubClass conforms to MySubClassDelegate protocol.

To further clairfy:

@interface MySubClassTester : NSObject {

}

@implementation MySubClassTester

- (void) one { 
    MySubClass *subclass = [[MySubClass alloc] init];
    subclass.delegate = self;
}

@end

will produce the warning: class 'MySubClassTester' does not implement the 'UITextViewDelegate' protocol

I want it to produce the warning about not implementing ‘MySubClassDelegate’ protocol instead.

  • 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-14T23:40:59+00:00Added an answer on May 14, 2026 at 11:40 pm

    The UITextView defines its delegate as

    @property(nonatomic, assign) id<UITextViewDelegate> delegate
    

    meaning it conforms to UITextViewDelegate, and that’s what compiler checks. If you want to use the new protocol, you need to redefine delegate to conform to your protocol:

    @interface MySubClass : UITextView {
    }
    @property(nonatomic, assign) id<MySubClassDelegate> delegate   
    @end
    

    The compiler shouldn’t give any more warnings.

    [Update by fess]

    … With this the compiler will warn that the accessors need to be implemented… [I implemented this:]

    -(void) setDelegate:(id<MySubClassDelegate>) delegate {
    [super setDelegate: delegate];
    }
    - (id) delegate {
    return [super delegate];
    }
    

    “

    [My update]

    I believe it should work if you only make a @dynamic declaration instead of reimplementing the method, as the implementation is already there:

    @dynamic delegate;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to use SwingWorker subclass multiple times. Is this possible?
I want to create a subclass that extends the CallableStatement object. I want to
I have an Offer class (NSManagedObject subclass) that I want to use to handle
I want to change all objects that match a condition to use a specific/new
I am using the iPhone toolchain on Linux and so I have no Interface
I'm looking to do the opposite of what Django's proxy model does. I want
I want to change the background color of a custom view. I have a
I want to ask a question about the objective C. When I study the
I have a base class, FooBase. On it are a few standard read/write properties.
I am trying to define an abstract class implementing Comparable. When I define the

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.