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

The Archive Base Latest Questions

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

I am trying to call a method in my root view controller from a

  • 0

I am trying to call a method in my root view controller from a child view controller such that when I change my options they will automatically update the root view, which will in turn update several other view controllers. For the second part I have used notifications, but for this first I am trying to use a delegate because it (so I have been lead to believe) is a good programming practice. I am having trouble making it work and know that I can set up another notification easily to do the job. Should I continue trying to implement the delegate or just use a notification?

  • 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:41:07+00:00Added an answer on May 13, 2026 at 4:41 pm

    Delegating is a good programming practice for many situations but that doesn’t mean you have to use it if you’re not comfortable with it. Both delegating and notifications help decouple the view controllers from each other, which is a good thing. Notifications might be a little easier to code and offer the advantage that multiple objects can observe one notification. With delegates, such a thing cannot be done without modifying the delegating object (and is unusual).

    Some advantages of delegating:

    • The connection between delegating object and delegate is made clearer, especially if implementing the delegate is mandatory.
    • If more than one type of message has to be passed from delegatee to delegate, delegating can make this clearer by specifying one delegate method per message. For notifications, you can use multiple notification names but all notifications end up in the same method on the side of the observer (possibly requiring a nasty switch statement).

    Only you can decide what pattern is more appropriate for you. In any case, you should consider not having your view controller send the notification or the delegate message. In many cases, the view controller should change the model and then the model should inform its observers or its delegate that it has been changed.

    Implementing a delegate pattern is simple:

    1. In your ChildViewController.h, declare the delegate protocol that the delegate must implement later:

      @protocol ChildViewControllerDelegate <NSObject>
      @optional
      - (void)viewControllerDidChange:(ChildViewController *)controller;
      @end
      
    2. At the top of the file, create an instance variable to hold the pointer to the delegate in your ChildViewController:

      @protocol ChildViewControllerDelegate;
      @interface ChildViewController : UIViewController {
          id <ChildViewControllerDelegate> delegate;
          ...
      }
      @property (assign) id <ChildViewControllerDelegate> delegate;
      ...
      @end
      
    3. In RootViewController.h, make your class conform to the delegate protocol:

      @interface RootViewController : UIViewController <ChildViewControllerDelegate> {
      ...
      
    4. In the RootViewController implementation, implement the delegate method. Also, when you create the ChildViewController instance, you have to assign the delegate.

      @implement RootViewController
      ...
      // in some method:
      ChildViewController *controller = [[ChildViewController alloc] initWithNibName:...
      controller.delegate = self;
      ...
      - (void)viewControllerDidChange:(ChildViewController *)controller {
          NSLog(@"Delegate method was called.");
      }
      ...
      
    5. In the ChildViewController implementation, call the delegate method at the appropriate time:

      @implementation ChildViewController
      ...
      // in some method:
      if ([self.delegate respondsToSelector:@selector(viewControllerDidChange:)]) {
          [self.delegate viewControllerDidChange:self];
      }
      ...
      

    That’s it. (Note: I have written this from memory so there are probably some typos/bugs in it.)

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

Sidebar

Related Questions

I am working with ASP.net. I am trying to call a method that exists
I am trying to achieve a JQuery AJAX call to a controller action method
I am trying to call a shell script that sets a bunch of environment
I'm trying to call a web service from Excel 2003 module. The way i've
I'm trying to call a method of the superclass by using a variable method
Here's how I set up my app. I have a root view that loads
I am trying to create a permanent wmi event consumer that will wait for
When trying to call Close or Dispose on an SqlDataReader i get a timeout
I'm trying to call an Antlr task in my Ant build.xml as follows: <path
I'm trying to call a function after I load some XML into Actionscript, and

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.