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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:57:07+00:00 2026-06-01T08:57:07+00:00

I’m working on a project after my ex-colleague. The code was great except for

  • 0

I’m working on a project after my ex-colleague. The code was great except for one,

Main Controller

@interface MainController : UIViewController {

}

@property (nonatomic, strong) IBOutlet HeaderBar *headerBar;

- (void)setup;
- (IBAction)refreshHeader;

@end


@implementation MainController 

- (void)setup{
    HeaderBar *hb = [[HeaderBar alloc] initWithNibNames:@"HeaderBar"];
    self.headerBar = hb;
}

- (IBAction)refreshHeader {
    //Do something with headerBar's properties
    //For example, [self.headerBar someiVar];
}

Then, there is a button as a subview of HeaderBar view. This button was tied with FirstResponder’s method, which appears to be refreshHeader

The code works fine as he wanted. But, even I’m new to iOS Development and I’m not quite understand about the FirstResponder yet. I don’t feel right with this design approach.

Since that button belongs to headerBar’s view. It should tied to headerBar’s method, right?
(assume that headerBar is a controller too)
Then, find a way to send a data/result/message from headerBar to MainController instead of send it to MainController directly by using firstResponder.

If that’s so, how could I send data/result/message to one of MainController’s method from a HeaderBar’s method instead of using the approach which appearing in other part of the code. (Which I feel not good about it too, it looks weird. It looks like, create a relation between two controller, in a wrong way.)

Main Controller

- (void)anotherSetup{
    FooterBar *fb = [[FooterBar alloc] initWithNibNames:@"FooterBar"];
    fb.mainController = self;
    self.footerBar = fb;
}

FooterBar

#import "MainController.h"

@interface FooterBar : UIViewController {

}

@property (nonatomic, strong) MainController *mainController;

- (void)someMethod;

@end

@implementation FooterBar
@synthesize mainController;

- (void)someMethod {
    [self.mainController someMainControllerMethod];
}

I read some other related questions, most of them said that the other approach is to define Protocal and Delegate, Is it the best way to do this? Is it the only way? Instead of two controller communicate with each other.

Any suggestion is welcome, correct my misunderstanding is welcome too. I will have to work on this project for months and it’s only at the second phase from five. So, I’d love to have least false design as possible.

Best Regards

P.S. I’m sorry if the code isn’t correct, it isn’t the actual code. Something may not correct, but, hope you guys can see the picture.

  • 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-01T08:57:09+00:00Added an answer on June 1, 2026 at 8:57 am

    Yes, this is the best way to do it. It’s called Delegation Design Pattern. And that’s actually having two controllers communicating with each other.

    The only issue I see here is that you retain the MainController in FooterBar. You shouldn’t do this, as it leads to retain cycle which blocks objects from being deallocated.(object A retains B, and obj B retains A, so their retain count will never be 0).

    So instead of having (at Footerbar):

    @property (nonatomic, strong) MainController *mainController;
    

    you should have:

    @property (nonatomic, assign) MainController *mainController;
    

    Or to be more generic(if needed), you can create a protocol describing needed methods for delegate. And then make MainController implement that protocol.

    //FooterBar.h
    @protocol FooterBarDelegate <NSObject>
    
    -(void)aNeededMethod;
    
    @end
    @interface FooterBar : UIViewController {
    
    }
    
    @property (nonatomic, assign) id<FooterBarDelegate> mainController;
    
    - (void)someMethod;
    
    @end
    

    and then

    //MainController.h
    #import "FooterBar.h"
    @interface MainController : UIViewController <FooterBarDelegate> {
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm making a simple page using Google Maps API 3. My first. One marker
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.