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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:03:00+00:00 2026-06-12T01:03:00+00:00

I have a ViewController, and a UIView. The UIView has a delegate, and the

  • 0

I have a ViewController, and a UIView.
The UIView has a delegate, and the delegate function is set in the ViewController.

All I want to do, is have the delegate function defined in a separate file. So the UIView.m #imports the separate file, instead of all the ViewControllers which use the UIView.

I believe this is a standard procedure, but keep falling over myself trying to get it to work. 😐 Would really appreciate some help. Thanks.

myViewController.h

#import <UIKit/UIKit.h>
#import "myUIView.h"
@protocol ModalViewDelegate                     
-(void)didReceiveMessage:(NSString *)message;   
@end
@interface myViewController : UIViewController <ModalViewDelegate>
@property (nonatomic, strong) myUIView *myUIViewItem;
@end

myViewController.m

#import "myViewController.h"
#import "myUIView.h"
@interface myViewController ()
@end
@implementation myViewController

@synthesize myUIViewItem;
- (void)didReceiveMessage:(NSString *)message { //<<< THIS IS WHAT
    NSLog(@"Message from button: %@", message); //<<< NEEDS MOVING
}
- (void)viewDidLoad
{
…
myUIViewItem.delegate = self;
…

myUIView.h

#import <UIKit/UIKit.h>
@protocol ModalViewDelegate;
@interface myUIView : UIView {
    id<ModalViewDelegate> delegate;
}
@property (nonatomic, strong) id<ModalViewDelegate> delegate;

myUIView.m

#import "myUIView.h"
#import "myViewController.h"
@implementation myUIView
@synthesize delegate;
...
[delegate didReceiveMessage:@"Data from UIView!"];
  • 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-12T01:03:01+00:00Added an answer on June 12, 2026 at 1:03 am

    Based on your comment:

    I want to have the function ‘didReceiveMessage’ defined in a SEPARATE
    file. So that I don’t have to repeat it in every ViewController that
    uses the UIView and delegate. e.g. ModalViewDelegate_Action.h and
    ModalViewDelegate_Action.m

    The way I was given was to use a subclass, and that’s been working great for me. In my iOS projects I have a class called BaseViewController, which is a subclass of UIViewController. I put lots of code in it related to HUD management, NSOperations management, etc. Then virtually all my view controllers are subclasses of it.

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

Sidebar

Related Questions

I want to have a ViewController that has a table view on the top
I have a viewController that has a tableView and a custom loading UIView that
I have a viewController that has a UIView as a subview, I was wondering
I have one ViewController, in this i have added one Custom UIView named as
I have a ViewController that includes its own .nib file, I am wanting to
I have a ViewController that has its own NIB. I would like to embed
I have a custom UIView called TiledImage which has a single property named tiledImage
I have a xib-file with a small UIView on it, which in turn contains
I have one single MainViewController which has of course it's one main UIView. I
I have a ViewController with a nib which have a UIView and a UITableView

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.