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.
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: