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.
Thanks, a bunch. (thanks brad)