I created a class that wraps a UITextView and adds some ui elements. I want the new class\' API to be identical with UITextView, so I use message forwarding (listing below)
Simple solution is to use dynamic typing and declare aMyTextView
as id
, the warnings will go away.
Declare a category that provides the method declarations of the methods you are forwarding:
@interface MyTextField (ImGonnaLetYouFinishButFirstImForwardingThese)
... methods you want to forward here ...
@end
No need to provide an @implementation.
Note that this is a fairly atypical pattern. Not fairly, very. There should be no reason why you can't subclass. You say Subclassing UITextView is also out of the question, because I need to insert views below the text view, but that isn't true.
If I subclass UITextField, all I can do with the other views is to add them as subviews, which means they will be on top of the text field. I guess I could modify drawRect:... Is that what you would suggest? Or what do you have up your sleeve there?
If you need a group, create a UIView subclass that manages the various subviews appropriately, no forwarding necessary. Then you can order the views however you like.
Forwarding is used extremely rarely. Down that path lies madness. It really sounds like your design is a bit in the weeds, but there isn't enough information to really say anything more specific.