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

  • SEARCH
  • Home
  • 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 597339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:16:11+00:00 2026-05-13T16:16:11+00:00

I created a class that wraps a UITextView and adds some ui elements. I

  • 0

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) to relay messages between the wrapped text view and the delegate.

The irritating thing is that the compiler issues warnings for method invocations on instances of my forwarding class. For example, an error will be generated for the following line:

[aMyTextView setContentOffset:CGPointZero animated:YES];

So I am forced to declare and create “manually forwarding” implementations for these methods, which defeats the whole purpose of using message forwarding.

- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
{
    [_textView setContentOffset:contentOffset animated:animated];
}

I know the usual way of getting around this is to use one of the performSelector: methods, but this is a) cumbersome when some arguments are not NSObjects (although Erica Sadun’s extensions are a big help), b) again, completely contrary to the intention of creating a transparent wrapper.

(Subclassing UITextView is also out of the question, because I need to insert views below the text view.)

Is there a way to get around this?

Listing 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
{
    // First, try to find it in the UITextView
    if ([_textView respondsToSelector:selector])
    {
        return [_textView methodSignatureForSelector:selector];
    }
    // Then try the delegate
    else if ([_delegate respondsToSelector:selector])
    {
        return [_delegate methodSignatureForSelector:selector];
    }
    else
    {
        return [super methodSignatureForSelector: selector];
    }
}

- (void)forwardInvocation:(NSInvocation *)invocation
{
    SEL aSelector = [invocation selector];

    if ([_textView respondsToSelector:aSelector])
    {
        [invocation invokeWithTarget:_textView];
    }
    else if ([_delegate respondsToSelector:aSelector])
    {
        [invocation invokeWithTarget:_delegate];
    }
    else
    {
        [self doesNotRecognizeSelector:aSelector];
    }
}
. . .
@end
  • 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-13T16:16:11+00:00Added an answer on May 13, 2026 at 4:16 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 508k
  • Answers 508k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No problem if your underlying shell is bash, since you… May 16, 2026 at 4:14 pm
  • Editorial Team
    Editorial Team added an answer The easiest way is to hold the current post's id… May 16, 2026 at 4:14 pm
  • Editorial Team
    Editorial Team added an answer You might want to check out Sphinx. It's a full… May 16, 2026 at 4:14 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I want to create a class that wraps another class so that when a
A common pattern in C++ is to create a class that wraps a lock
I created a calculator class that does basic +,-, %, * and sin, cos,
I want to isolate all my code from the IoC container library that I
I have created the following project structure for my new asp.net mvc project any
I recently read that Java now sports initialisation blocks like the following: class C
So, I'm trying to create a div class that will display in a row
I would like to design a simple application (without j2ee and jms) that can
I have an object, lets call it UnSerializableObject, that I can't and change that
I am using the rather fantastic jQuery multiple select plugin, ASM select This plugin

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.