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 8755177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:47:51+00:00 2026-06-13T13:47:51+00:00

The bulk of the code for my app is in a ‘m’ file called

  • 0

The bulk of the code for my app is in a ‘m’ file called MyViewController. The app implements a custom UIView which contains a UIWebView object. The code for the UIView and UIWebView is kept in a separate ‘m’ file called CustomUIView.

I have managed to override clicks on URL hyperlinks in the UIWebView object using a delegate. However, I would like to have these clicks launch a method that is stored in my main app code. This method is called “popupView”, and takes a single argument, “inputArgument”. The inputArgument is the text of the URL the user clicks on. In fact, this method is the very same one that causes my custom UIView to launch.

Anyway, what I’d like to do is have my overridden URL clicks cause the popupView method to launch, thus causing another UIView to open on top of the one that was clicked on.

The problem is that the ‘m’ file where the URL clicks are detected can’t see the ‘popupView’ method as it is included in the MyViewController ‘m’ file. How do I call the popupView method from another ‘m’ file?

  • 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-06-13T13:47:52+00:00Added an answer on June 13, 2026 at 1:47 pm

    Directly

    1. Declare MyViewController‘s method -popupView: in MyViewController.h.
    2. #import MyViewController.h in CustomUIView.m.
    3. Give CustomUIView a reference to the [one] instance of MyViewController, for example by way of an @property declared in CustomUIView.h.

    For (1), the @interface of MyViewController (in MyViewController.h) should look a bit like this

    @interface MyViewController : UIViewController
    {
        //....
    }
    - (void)popupView:(NSString *)urlText;
    //....
    @end
    

    For (2), UIViewController.m should have the following somewhere near the top

    #import "CustomUIView.h"
    #import "MyViewController.h"
    

    For (3), the @interface in CustomUIView.h should look something like

    @interface CustomUIView : UIView
    {
        //....
    }
    @property (nonatomic, weak) MyViewController *viewController;
    @end
    

    This property will need to be set some time after the instance of CustomUIView owned by MyViewController is created. If your CustomUIView is in MyViewController.xib, you can set this property on it by adding the keyword IBOutlet to the property’s declaration like this

    @property (nonatomic, weak) IBOutlet MyViewController *viewController;
    

    and pointing this property to "File’s Owner" in the XIB. If instead, you create the CustomUIView programmatically, you can set this property on it as soon as you have initialized it.

    Delegate

    This, however, is far from being a best practice. It would be much better to make use of the delegate pattern. To do this, you’ll need to

    1. Define a delegate protocol.
    2. Add a "delegate" @property to CustomUIView.
    3. Call the delegate methods on the delegate object at the appropriate times.
    4. Implement the protocol in MyViewController.
    5. Set the "delegate" @property of the instance of CustomUIView owned by the MyViewController instance to be the MyViewController instance.

    Let’s call our delegate protocol something imaginative like CustomUIViewDelegate. For (1), we’ll declare it at the top of CustomUIView.h as follows:

    @class CustomUIView;
    
    @protocol CustomUIViewDelegate <NSObject>
    - (void)customUIView:(CustomUIView *)customView didSelectURLText:(NSString *)urlText;
    @end
    

    Notice that we’ve had to forward declare our class CustomUIView so that the compiler is able to make sense of the type of the first argument in the protocol method customUIView:didSelectURLText:.

    For (2), we’ll do something quite similar to (3) above: Your CustomUIView @interface will look something like

    @interface CustomUIView : UIView
    {
        //....
    }
    @property (nonatomic, weak) id<CustomUIViewDelegate> *delegate;
    @end
    

    Again, if we’re going to set this property in Interface Builder, we’ll need to use the IBOutlet keyword to announce it to IB:

    @property (nonatomic, weak) IBOutlet id<CustomUIViewDelegate> *delegate;
    

    For (3), we need to call the delegate method customUIView:didSelectURLText: on our delegate object self.delegate at the appropriate time.

    In your question, you wrote

    I have managed to override clicks on URL hyperlinks in the UIWebView object using a delegate.

    So, let’s say that CustomUIView has an instance method

    - (void)didSelectURL:(NSURL *)url
    {
        //....
    }
    

    which you call when the user selects a link in the UIWebView. The CustomUIView‘s delegate needs to be informed of this:

    - (void)didSelectURL:(NSURL *)url
    {
        //...
        if ([self.delegate respondsToSelector:@selector(customUIView:didSelectURLText:)]) {
        {
            [self.delegate customUIView:self didSelectURLText:url.absoluteString];
        }
    }
    

    Notice that we check first whether the CustomUIView instance’s delegate object implements the selector of interest (customUIView:didSelectURLText:) by calling respondsToSelector: on it.

    For (4), we’ll need first to add <CustomUIViewDelegate> to MyViewController‘s @interface declaration and be sure to #import CustomUIView.h into the file where we use the symbol CustomUIViewDelegate. Our MyViewController‘s @interface will look something like this:

    #import "CustomUIView.h"
    
    @interface MyViewController : UIViewController <CustomUIViewDelegate>
    {
        //....
    }
    //....
    @end
    

    More importantly, we need to implement the CustomUIViewDelegate protocol in MyViewController‘s @implementation; so far we’ve only declared that MyViewController adopts it.

    To do this, since our protocol consists of only one method, we’ll need only to add our own implementation of -customUIView:didSelectURLText:. Our MyViewController‘s @implementation will look something like this:

    #import "MyViewController.h"
    
    @implementation MyViewController
    
    //....
    
    - (void)popupView:(NSString *)urlText
    {
        //....
    }
    
    #pragma mark - CustomUIViewDelegate
    
    - (void)customUIView:(CustomUIView *)customView didSelectURLText:(NSString *)urlText
    {
        [self popupView:urlText];
    }
    
    //....
    
    @end
    

    Finally, for (5), we’ll need to set the delegate property of the instance of CustomUIView owned by the MyViewController instance. I don’t know enough about MyViewController‘s relationship with its CustomUIView instance to do describe how to do this definitively, but I’ll provide an example: I’ll assume that you programmatically, in -[MyViewController loadView] add the CustomUIView as a subview of MyViewController‘s view. So your implementation of -loadView looks a bit like this:

    - (void)loadView
    {
        [super loadView];
        
        //....
        
        CustomUIView *customView = //....        
        //....
        [self.view addSubview:customView];
        
        //....
        
    }
    

    All that remains to do at this point is to set the delegate @property of the local variable customView to self:

    customView.delegate = self;
    

    Edit: Updated (5) in light of new information about the relationship between CustomUIView and MyViewController.

    In your comment, you write that your CustomUIView is added as a subview of cvc.view where cvc is an instance of CustomUIViewController in CustomUIView‘s method -[CustomUIView show]. On account of this, you note that writing customView.delegate = self; is the same as writing self.delegate = self, which is clearly not what you want to do.

    You want to set the CustomUIView‘s delegate property to be the instance of MyViewController. Consequently, your method -[CustomUIView show] should look something like

    - (void)show
    {
        //....
        [cvc.view addSubview:self];
    
        self.delegate = mvc;
    }
    

    where mvc is the instance of MyViewController.

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

Sidebar

Related Questions

I'm doing a bulk insert of a CSV file into SQL Server 2005, using
I built an app that takes in a CSV as a bulk feed and
I have a csv format file, which I want to import to sql server
I want to bulk upload csv file data to sql server 2005 from c#
I'm writing a bulk insert script using Django's ORM + custom raw SQL. The
I have VBScript code which launches QuickTest Professional, executes a series of QTP tests,
I'm doing a BULK INSERT into a table using a FMT format file, but
I'm working on an app which encodes text to QR codes. Currently I have
I'm creating a console app to process a file and then move it to
If I want to keep the bulk of my code for processing command line

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.