I created a class that wraps a UITextView and adds some ui elements. I want the new class API to be identical with the UITextView, so I use message forwarding (the list below) to send messages between the wrapped text view and the delegate.
It is annoying that the compiler generates warnings for method calls on instances of my redirect class. For example, an error will be generated for the following line:
[aMyTextView setContentOffset:CGPointZero animated:YES]
Therefore, I have to declare and create a โmanual redirectโ for these methods, which is detrimental to the whole purpose of using message forwarding.
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated { [_textView setContentOffset:contentOffset animated:animated]; }
I know that the usual way around this is to use one of the performSelector: methods, but it is a) cumbersome when some arguments are not NSObjects (although Erica Sadun extensions are a big help), b) again, completely contradicts the intention to create a transparent shell.
(Subclassing UITextView is also out of the question, because I need to insert the views under the text view.)
Is there any way around this?
List of all relevant parts of the class:
@interface MyTextField : UIView<UITextViewDelegate> { UIImageView* _border; UITextView* _textView; UIButton* _clearButton; NSObject<UITextViewDelegate>* _delegate; } @implementation MWTextField . . . // Forwards messages in both directions (textView <--> delegate) #pragma mark Message forwarding // Protocol messages will only be sent if respondsToSelector: returns YES - (BOOL)respondsToSelector:(SEL)aSelector { if ([_delegate respondsToSelector:aSelector]) return YES; else return [super respondsToSelector:aSelector]; } - (NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
source share